generated from bcgov/EPIC.scaffold
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #186 from dinesh-aot/COMP-298
Create inspection requirement
- Loading branch information
Showing
10 changed files
with
424 additions
and
9 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
compliance-api/migrations/versions/6c3b6755e2dc_inspection_requirement_patches.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
"""inspection_requirement_patches | ||
Revision ID: 6c3b6755e2dc | ||
Revises: a684c47ac3e8 | ||
Create Date: 2025-01-02 18:17:21.124175 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = '6c3b6755e2dc' | ||
down_revision = 'a684c47ac3e8' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table('inspection_req_detail_documents', schema=None) as batch_op: | ||
batch_op.alter_column('document_title', | ||
existing_type=sa.VARCHAR(), | ||
nullable=True, | ||
existing_comment='The title of the document') | ||
|
||
with op.batch_alter_table('inspection_requirements', schema=None) as batch_op: | ||
batch_op.add_column(sa.Column('sort_order', sa.Integer(), nullable=False, comment='The order of requirements')) | ||
batch_op.alter_column('enforcement_action_id', | ||
existing_type=sa.INTEGER(), | ||
nullable=True, | ||
existing_comment='The enforcement action taken on the requirement') | ||
batch_op.alter_column('compliance_finding_id', | ||
existing_type=sa.INTEGER(), | ||
nullable=True, | ||
existing_comment='Compliance finding of the requirement') | ||
batch_op.create_index(batch_op.f('ix_inspection_requirements_inspection_id'), ['inspection_id'], unique=False) | ||
|
||
with op.batch_alter_table('inspection_requirements_version', schema=None) as batch_op: | ||
batch_op.add_column(sa.Column('sort_order', sa.Integer(), autoincrement=False, nullable=True, comment='The order of requirements')) | ||
batch_op.add_column(sa.Column('sort_order_mod', sa.Boolean(), server_default=sa.text('false'), nullable=False)) | ||
batch_op.create_index(batch_op.f('ix_inspection_requirements_version_inspection_id'), ['inspection_id'], unique=False) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table('inspection_requirements_version', schema=None) as batch_op: | ||
batch_op.drop_index(batch_op.f('ix_inspection_requirements_version_inspection_id')) | ||
batch_op.drop_column('sort_order_mod') | ||
batch_op.drop_column('sort_order') | ||
|
||
with op.batch_alter_table('inspection_requirements', schema=None) as batch_op: | ||
batch_op.drop_index(batch_op.f('ix_inspection_requirements_inspection_id')) | ||
batch_op.alter_column('compliance_finding_id', | ||
existing_type=sa.INTEGER(), | ||
nullable=False, | ||
existing_comment='Compliance finding of the requirement') | ||
batch_op.alter_column('enforcement_action_id', | ||
existing_type=sa.INTEGER(), | ||
nullable=False, | ||
existing_comment='The enforcement action taken on the requirement') | ||
batch_op.drop_column('sort_order') | ||
|
||
with op.batch_alter_table('inspection_req_detail_documents', schema=None) as batch_op: | ||
batch_op.alter_column('document_title', | ||
existing_type=sa.VARCHAR(), | ||
nullable=False, | ||
existing_comment='The title of the document') | ||
|
||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
compliance-api/src/compliance_api/resources/inspection_requirement.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
"""InspectionRequirementResource.""" | ||
|
||
from http import HTTPStatus | ||
|
||
from flask_restx import Namespace, Resource | ||
|
||
from compliance_api.auth import auth | ||
from compliance_api.schemas.inspection_requirement import InspectionRequirementCreateSchema, InspectionRequirementSchema | ||
from compliance_api.services import InspectionRequirementService | ||
from compliance_api.utils.util import cors_preflight | ||
|
||
from .apihelper import Api as ApiHelper | ||
|
||
|
||
API = Namespace("requirements", description="Endpoints for Inspection Requirement") | ||
inspection_requirement_create_model = ApiHelper.convert_ma_schema_to_restx_model( | ||
API, InspectionRequirementCreateSchema(), "InspectionRequirement" | ||
) | ||
|
||
inspection_requirement_list_model = ApiHelper.convert_ma_schema_to_restx_model( | ||
API, InspectionRequirementSchema(), "InspectionRequirementList" | ||
) | ||
|
||
|
||
@cors_preflight("GET, OPTIONS, POST") | ||
@API.route("", methods=["POST", "GET", "OPTIONS"]) | ||
class InspectionRequirements(Resource): | ||
"""InspectionRequirements.""" | ||
|
||
@staticmethod | ||
@ApiHelper.swagger_decorators(API, endpoint_description="Get all requirements by inspection") | ||
@auth.require | ||
@API.response(code=200, description="Success", model=[inspection_requirement_list_model]) | ||
def get(inspection_id): | ||
"""Get requirements by inspection id.""" | ||
requirements = InspectionRequirementService.get_all(inspection_id) | ||
return InspectionRequirementSchema(many=True).dump(requirements), HTTPStatus.OK | ||
|
||
@staticmethod | ||
@ApiHelper.swagger_decorators(API, endpoint_description="Create an inspection") | ||
@API.expect(inspection_requirement_create_model) | ||
@API.response( | ||
code=201, | ||
model=inspection_requirement_list_model, | ||
description="InspectionCreated", | ||
) | ||
@API.response(400, "Bad Request") | ||
@auth.require | ||
def post(inspection_id): | ||
"""Create an inspection.""" | ||
requirement_data = InspectionRequirementCreateSchema().load(API.payload) | ||
created_requirement = InspectionRequirementService.create( | ||
inspection_id, requirement_data | ||
) | ||
return ( | ||
InspectionRequirementSchema().dump(created_requirement), | ||
HTTPStatus.CREATED, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.