-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
act sections in extension input (#1108)
- Loading branch information
1 parent
481bf55
commit 1b04067
Showing
13 changed files
with
162 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Copyright © 2019 Province of British Columbia | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Resource for Act Section endpoints.""" | ||
from http import HTTPStatus | ||
|
||
from flask import jsonify, request | ||
from flask_restx import Namespace, Resource, cors | ||
|
||
from api.services import ActSectionService | ||
from api.utils import auth, constants, profiletime | ||
from api.utils.caching import AppCache | ||
from api.utils.util import cors_preflight | ||
|
||
from api.schemas import request as req | ||
from api.schemas import response as res | ||
|
||
API = Namespace("act-sections", description="ActSections") | ||
|
||
|
||
@cors_preflight("GET") | ||
@API.route("", methods=["GET", "OPTIONS"]) | ||
class ActSections(Resource): | ||
"""Endpoint resource to return sub types based on type id""" | ||
|
||
@staticmethod | ||
@cors.crossdomain(origin="*") | ||
@auth.require | ||
@profiletime | ||
@AppCache.cache.cached(timeout=constants.CACHE_DAY_TIMEOUT, query_string=True) | ||
def get(): | ||
"""Return all sub_types based on type_id.""" | ||
args = req.ActSectionQueryParameterSchema().load(request.args) | ||
act_sections = ActSectionService.find_by_ea_act(args) | ||
return jsonify(res.ActSectionResponseSchema(many=True).dump(act_sections)), HTTPStatus.OK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
epictrack-api/src/api/schemas/request/act_section_request.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Copyright © 2019 Province of British Columbia | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the 'License'); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an 'AS IS' BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Act Sections resource's input validations""" | ||
from marshmallow import fields, validate | ||
|
||
from .base import BasicRequestQueryParameterSchema | ||
|
||
|
||
class ActSectionQueryParameterSchema(BasicRequestQueryParameterSchema): | ||
"""Type id path parameter schema""" | ||
|
||
ea_act_id = fields.Int( | ||
metadata={"description": "The id of the EA Act"}, | ||
validate=validate.Range(min=1) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
epictrack-api/src/api/schemas/response/act_section_response.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"""ActSection model schema""" | ||
from marshmallow import EXCLUDE | ||
|
||
from api.models import ActSection | ||
from api.schemas.base import AutoSchemaBase | ||
|
||
|
||
class ActSectionResponseSchema( | ||
AutoSchemaBase | ||
): # pylint: disable=too-many-ancestors,too-few-public-methods | ||
"""Type model schema class""" | ||
|
||
class Meta(AutoSchemaBase.Meta): | ||
"""Meta information""" | ||
|
||
model = ActSection | ||
unknown = EXCLUDE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Copyright © 2019 Province of British Columbia | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the 'License'); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an 'AS IS' BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Service to manage ActSection.""" | ||
from flask import current_app | ||
|
||
from api.models import ActSection | ||
|
||
|
||
class ActSectionService: # pylint:disable=too-few-public-methods | ||
"""Service to manage sub type related operations""" | ||
|
||
@classmethod | ||
def find_by_ea_act(cls, args: dict): | ||
"""Find sub types by type_id""" | ||
current_app.logger.debug(f"find act sections by params {args}") | ||
act_sections = ActSection.find_by_params(args) | ||
return act_sections |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
epictrack-web/src/services/actSectionService/actSectionService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Endpoints from "../../constants/api-endpoint"; | ||
import http from "../../apiManager/http-request-handler"; | ||
|
||
class ActSectionService { | ||
async getActSectionsByEaAct(eaActId?: number) { | ||
return await http.GetRequest( | ||
Endpoints.ActSections.ACT_SECTIONS + `?ea_act_id=${eaActId}` | ||
); | ||
} | ||
} | ||
|
||
export default new ActSectionService(); |