Skip to content

Commit

Permalink
options apis for requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
dinesh-aot committed Dec 26, 2024
1 parent 04fe26e commit dd9b572
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 @@ -36,6 +36,8 @@
from .requirement_source import API as REQUIREMENT_SOURCE_API
from .staff_user import API as USER_API
from .topic import API as TOPIC_API
from .enforcement_action import API as ENFORCEMENT_ACTION_API
from .compliance_finding import API as COMPLIANCE_FINDING_API


__all__ = ("API_BLUEPRINT", "OPS_BLUEPRINT")
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 @@ -23,3 +23,5 @@
from .requirement_source import RequirementSourceService
from .staff_user import StaffUserService
from .topic import TopicService
from .enforcement_action import EnforcementActionService
from .compliance_finding import ComplianceFindingService
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 dd9b572

Please sign in to comment.