Skip to content

Commit

Permalink
Merge pull request bcgov#179 from dinesh-aot/requirement_apis
Browse files Browse the repository at this point in the history
options apis for requirement
  • Loading branch information
nitheesh-aot authored and dinesh-aot committed Dec 27, 2024
2 parents 04fe26e + dd9b572 commit 25e8f3c
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 2 deletions.
4 changes: 4 additions & 0 deletions compliance-api/src/compliance_api/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
from .apihelper import Api
from .case_file import API as CASE_FILE_API
from .complaint import API as COMPLAINT_API
from .compliance_finding import API as COMPLIANCE_FINDING_API
from .continuation_report import API as CONTINUATION_REPORT_API
from .enforcement_action import API as ENFORCEMENT_ACTION_API
from .inspection import API as INSPECTION_API
from .ops import API as OPS_API
from .position import API as POSITION_API
Expand Down Expand Up @@ -81,3 +83,5 @@
API.add_namespace(COMPLAINT_API)
API.add_namespace(REQUIREMENT_SOURCE_API)
API.add_namespace(CONTINUATION_REPORT_API)
API.add_namespace(ENFORCEMENT_ACTION_API)
API.add_namespace(COMPLIANCE_FINDING_API)
53 changes: 53 additions & 0 deletions compliance-api/src/compliance_api/resources/compliance_finding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# 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 compliance finding resource."""

from http import HTTPStatus

from flask_restx import Namespace, Resource

from compliance_api.auth import auth
from compliance_api.schemas import KeyValueSchema
from compliance_api.services import ComplianceFindingService
from compliance_api.utils.util import cors_preflight

from .apihelper import Api as ApiHelper


API = Namespace(
"compliance-findings",
description="Endpoints for compliance finding Management",
)

key_value_list_model = ApiHelper.convert_ma_schema_to_restx_model(
API, KeyValueSchema(), "List"
)


@cors_preflight("GET, OPTIONS")
@API.route("", methods=["GET", "OPTIONS"])
class ComplianceFindings(Resource):
"""Resource for managing compliance findings."""

@staticmethod
@API.response(code=200, description="Success", model=[key_value_list_model])
@ApiHelper.swagger_decorators(
API, endpoint_description="Fetch all compliance findings"
)
@auth.require
def get():
"""Fetch all compliance findings."""
compliance_findings = ComplianceFindingService.get_compliance_findings()
list_schema = KeyValueSchema(many=True)
return list_schema.dump(compliance_findings), HTTPStatus.OK
53 changes: 53 additions & 0 deletions compliance-api/src/compliance_api/resources/enforcement_action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# 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 enforcement action resource."""

from http import HTTPStatus

from flask_restx import Namespace, Resource

from compliance_api.auth import auth
from compliance_api.schemas import KeyValueSchema
from compliance_api.services import EnforcementActionService
from compliance_api.utils.util import cors_preflight

from .apihelper import Api as ApiHelper


API = Namespace(
"enforcement-actions",
description="Endpoints for Enforcement Action Management",
)

key_value_list_model = ApiHelper.convert_ma_schema_to_restx_model(
API, KeyValueSchema(), "List"
)


@cors_preflight("GET, OPTIONS")
@API.route("", methods=["GET", "OPTIONS"])
class EnforcementActions(Resource):
"""Resource for managing enforcement actions."""

@staticmethod
@API.response(code=200, description="Success", model=[key_value_list_model])
@ApiHelper.swagger_decorators(
API, endpoint_description="Fetch all enforcement actions"
)
@auth.require
def get():
"""Fetch all enforcement actions."""
enforcement_actions = EnforcementActionService.get_enforcement_actions()
list_schema = KeyValueSchema(many=True)
return list_schema.dump(enforcement_actions), HTTPStatus.OK
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
)


@cors_preflight("GET, OPTIONS, POST")
@API.route("", methods=["POST", "GET", "OPTIONS"])
@cors_preflight("GET, OPTIONS")
@API.route("", methods=["GET", "OPTIONS"])
class RequirementSource(Resource):
"""Resource for managing requirement source."""

Expand Down
2 changes: 2 additions & 0 deletions compliance-api/src/compliance_api/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
from .agency import AgencyService
from .case_file import CaseFileService
from .complaint import ComplaintService
from .compliance_finding import ComplianceFindingService
from .continuation_report import ContinuationReportService
from .enforcement_action import EnforcementActionService
from .inspection import InspectionService
from .position import PositionService
from .project import ProjectService
Expand Down
12 changes: 12 additions & 0 deletions compliance-api/src/compliance_api/services/compliance_finding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""Compliance finding service."""

from compliance_api.models import ComplianceFindingOption as ComplianceFindingOptionModel


class ComplianceFindingService:
"""Compliance finding service."""

@classmethod
def get_compliance_findings(cls):
"""Get compliance finding options."""
return ComplianceFindingOptionModel.get_all(sort_by="sort_order")
12 changes: 12 additions & 0 deletions compliance-api/src/compliance_api/services/enforcement_action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""Enforcement Action service."""

from compliance_api.models import EnforcementActionOption as EnforcementActionOptionModel


class EnforcementActionService:
"""Enforcement action service."""

@classmethod
def get_enforcement_actions(cls):
"""Get enforcement actions."""
return EnforcementActionOptionModel.get_all(sort_by="sort_order")
14 changes: 14 additions & 0 deletions compliance-api/tests/integration/api/test_compliance_finding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""test suit for compliance findings."""
from http import HTTPStatus
from urllib.parse import urljoin


API_BASE_URL = "/api/"


def test_get_compliance_findings(client, auth_header):
"""Get compliance findings."""
url = urljoin(API_BASE_URL, "compliance-findings")
result = client.get(url, headers=auth_header)
assert len(result.json) == 3
assert result.status_code == HTTPStatus.OK
14 changes: 14 additions & 0 deletions compliance-api/tests/integration/api/test_enforcement_action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""test suit for enforcement actions."""
from http import HTTPStatus
from urllib.parse import urljoin


API_BASE_URL = "/api/"


def test_get_enforcement_actions(client, auth_header):
"""Get enforcement actions."""
url = urljoin(API_BASE_URL, "enforcement-actions")
result = client.get(url, headers=auth_header)
assert len(result.json) == 9
assert result.status_code == HTTPStatus.OK

0 comments on commit 25e8f3c

Please sign in to comment.