diff --git a/compliance-api/src/compliance_api/resources/__init__.py b/compliance-api/src/compliance_api/resources/__init__.py index e348051c..6f53248f 100644 --- a/compliance-api/src/compliance_api/resources/__init__.py +++ b/compliance-api/src/compliance_api/resources/__init__.py @@ -35,6 +35,7 @@ from .document_job import API as FILE_JOB_API from .document_type import API as DOCUMENT_TYPE_API from .enforcement_action import API as ENFORCEMENT_ACTION_API +from .first_nation import API as FIRST_NATION_API from .inspection import API as INSPECTION_API from .inspection_record import API as IR_API from .inspection_requirement import API as INSPECTION_REQUIREMENT_API @@ -126,3 +127,4 @@ API.add_namespace(SENTENCE_TYPE_OPTION_API, path="sentence-type-options") API.add_namespace(FILE_JOB_API, path="document-jobs") API.add_namespace(REPORT_API, path="reports") +API.add_namespace(FIRST_NATION_API, path="first-nations") diff --git a/compliance-api/src/compliance_api/resources/first_nation.py b/compliance-api/src/compliance_api/resources/first_nation.py new file mode 100644 index 00000000..f921dacc --- /dev/null +++ b/compliance-api/src/compliance_api/resources/first_nation.py @@ -0,0 +1,65 @@ +# Copyright © 2024 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. +"""API endpoints for managing First Nations resource.""" + +from http import HTTPStatus + +from flask_restx import Namespace, Resource + +from compliance_api.auth import auth +from compliance_api.services.epic_track_service.track_service import TrackService +from compliance_api.utils.util import cors_preflight + +from .apihelper import Api as ApiHelper + + +API = Namespace( + "first-nations", + description="Endpoints for First Nations Management", +) + + +@cors_preflight("GET, OPTIONS") +@API.route("", methods=["GET", "OPTIONS"]) +class FirstNations(Resource): + """Resource for fetching First Nations.""" + + @staticmethod + @API.response(code=200, description="Success") + @ApiHelper.swagger_decorators( + API, endpoint_description="Fetch all First Nations from EPIC.track" + ) + @auth.require + def get(): + """Fetch all First Nations.""" + first_nations = TrackService.get_first_nations() + return first_nations, HTTPStatus.OK + + +@cors_preflight("GET, OPTIONS") +@API.route("/", methods=["GET", "OPTIONS"]) +class FirstNation(Resource): + """Resource for fetching a single First Nation.""" + + @staticmethod + @API.response(code=200, description="Success") + @API.response(code=404, description="First Nation not found") + @ApiHelper.swagger_decorators( + API, endpoint_description="Fetch a First Nation by ID from EPIC.track" + ) + @auth.require + def get(first_nation_id: int): + """Fetch a First Nation by ID.""" + first_nation = TrackService.get_first_nation_by_id(first_nation_id) + return first_nation, HTTPStatus.OK diff --git a/compliance-web/src/hooks/useFirstNations.tsx b/compliance-web/src/hooks/useFirstNations.tsx index 4d287cf7..1fff9a16 100644 --- a/compliance-web/src/hooks/useFirstNations.tsx +++ b/compliance-web/src/hooks/useFirstNations.tsx @@ -1,10 +1,10 @@ import { FirstNation } from "@/models/FirstNation"; -import { requestTrackAPI } from "@/utils/axiosUtils"; +import { request } from "@/utils/axiosUtils"; import { useStaticQuery } from "@/hooks/useCustomQueries"; -/** FETCH First Nations from TRACK API */ +/** FETCH First Nations from Compliance API (proxied from TRACK API) */ const fetchFirstNations = (): Promise => { - return requestTrackAPI({ url: "/indigenous-nations", params: { is_active: true } }); + return request({ url: "/first-nations" }); };