Skip to content

Commit

Permalink
DocumentTypes GET
Browse files Browse the repository at this point in the history
  • Loading branch information
dinesh-aot committed Jan 3, 2025
1 parent eb270ab commit bdbf0f1
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 0 deletions.
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 @@ -29,6 +29,7 @@
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 .document_type import API as DOCUMENT_TYPE_API
from .enforcement_action import API as ENFORCEMENT_ACTION_API
from .inspection import API as INSPECTION_API
from .inspection_requirement import API as INSPECTION_REQUIREMENT_API
Expand Down Expand Up @@ -87,3 +88,4 @@
API.add_namespace(ENFORCEMENT_ACTION_API)
API.add_namespace(COMPLIANCE_FINDING_API)
API.add_namespace(INSPECTION_REQUIREMENT_API, path="inspections/<int:inspection_id>/requirements")
API.add_namespace(DOCUMENT_TYPE_API)
51 changes: 51 additions & 0 deletions compliance-api/src/compliance_api/resources/document_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# 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 document type 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 DocumentTypeService
from compliance_api.utils.util import cors_preflight

from .apihelper import Api as ApiHelper


API = Namespace(
"document-types",
description="Endpoints for Document Type 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 DocumentTypes(Resource):
"""Resource for managing document types."""

@staticmethod
@API.response(code=200, description="Success", model=[key_value_list_model])
@ApiHelper.swagger_decorators(API, endpoint_description="Fetch all document types")
@auth.require
def get():
"""Fetch all document types."""
document_types = DocumentTypeService.get_all()
list_schema = KeyValueSchema(many=True)
return list_schema.dump(document_types), HTTPStatus.OK
1 change: 1 addition & 0 deletions compliance-api/src/compliance_api/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from .complaint import ComplaintService
from .compliance_finding import ComplianceFindingService
from .continuation_report import ContinuationReportService
from .document_type import DocumentTypeService
from .enforcement_action import EnforcementActionService
from .inspection import InspectionService
from .inspection_requirement import InspectionRequirementService
Expand Down
12 changes: 12 additions & 0 deletions compliance-api/src/compliance_api/services/document_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""Document Type service."""

from compliance_api.models import DocumentType as DocumentTypeModel


class DocumentTypeService:
"""DocumentTypeService."""

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


API_BASE_URL = "/api/"


def test_get_document_type(client, auth_header):
"""Get document type."""
url = urljoin(API_BASE_URL, "document-types")
result = client.get(url, headers=auth_header)
assert len(result.json) == 2
assert result.status_code == HTTPStatus.OK

0 comments on commit bdbf0f1

Please sign in to comment.