Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compliance-api/src/compliance_api/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
65 changes: 65 additions & 0 deletions compliance-api/src/compliance_api/resources/first_nation.py
Original file line number Diff line number Diff line change
@@ -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("/<int:first_nation_id>", 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
6 changes: 3 additions & 3 deletions compliance-web/src/hooks/useFirstNations.tsx
Original file line number Diff line number Diff line change
@@ -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<FirstNation[]> => {
return requestTrackAPI({ url: "/indigenous-nations", params: { is_active: true } });
return request({ url: "/first-nations" });
};


Expand Down