-
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 #2866 from HHS/OPS-2836/Can-funding-received-api-e…
…ndpoint feat:Created-CAN-funding-received-endpoint
- Loading branch information
Showing
9 changed files
with
735 additions
and
2 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
...d/alembic/versions/2024_10_01_2048-acfeadc7868c_adding_events_for_can_funding_received.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,34 @@ | ||
"""adding events for can funding received | ||
Revision ID: acfeadc7868c | ||
Revises: d5610e0988b0 | ||
Create Date: 2024-10-01 20:48:34.638703+00:00 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
from alembic_postgresql_enum import TableReference | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = 'acfeadc7868c' | ||
down_revision: Union[str, None] = 'd5610e0988b0' | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.sync_enum_values('ops', 'opseventtype', ['CREATE_BLI', 'UPDATE_BLI', 'DELETE_BLI', 'SEND_BLI_FOR_APPROVAL', 'CREATE_PROJECT', 'CREATE_NEW_AGREEMENT', 'UPDATE_AGREEMENT', 'DELETE_AGREEMENT', 'CREATE_NEW_CAN', 'UPDATE_CAN', 'DELETE_CAN', 'CREATE_CAN_FUNDING_RECEIVED', 'UPDATE_CAN_FUNDING_RECEIVED', 'DELETE_CAN_FUNDING_RECEIVED', 'CREATE_CAN_FUNDING_BUDGET', 'UPDATE_CAN_FUNDING_BUDGET', 'DELETE_CAN_FUNDING_BUDGET', 'ACKNOWLEDGE_NOTIFICATION', 'CREATE_BLI_PACKAGE', 'UPDATE_BLI_PACKAGE', 'CREATE_SERVICES_COMPONENT', 'UPDATE_SERVICES_COMPONENT', 'DELETE_SERVICES_COMPONENT', 'CREATE_PROCUREMENT_ACQUISITION_PLANNING', 'UPDATE_PROCUREMENT_ACQUISITION_PLANNING', 'DELETE_PROCUREMENT_ACQUISITION_PLANNING', 'CREATE_DOCUMENT', 'UPDATE_DOCUMENT', 'LOGIN_ATTEMPT', 'LOGOUT', 'GET_USER_DETAILS', 'CREATE_USER', 'UPDATE_USER', 'DEACTIVATE_USER'], | ||
[TableReference(table_schema='ops', table_name='ops_event', column_name='event_type'), TableReference(table_schema='ops', table_name='ops_event_version', column_name='event_type')], | ||
enum_values_to_rename=[]) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.sync_enum_values('ops', 'opseventtype', ['CREATE_BLI', 'UPDATE_BLI', 'DELETE_BLI', 'SEND_BLI_FOR_APPROVAL', 'CREATE_PROJECT', 'CREATE_NEW_AGREEMENT', 'UPDATE_AGREEMENT', 'DELETE_AGREEMENT', 'CREATE_NEW_CAN', 'UPDATE_CAN', 'DELETE_CAN', 'CREATE_CAN_FUNDING_BUDGET', 'UPDATE_CAN_FUNDING_BUDGET', 'DELETE_CAN_FUNDING_BUDGET', 'ACKNOWLEDGE_NOTIFICATION', 'CREATE_BLI_PACKAGE', 'UPDATE_BLI_PACKAGE', 'CREATE_SERVICES_COMPONENT', 'UPDATE_SERVICES_COMPONENT', 'DELETE_SERVICES_COMPONENT', 'CREATE_PROCUREMENT_ACQUISITION_PLANNING', 'UPDATE_PROCUREMENT_ACQUISITION_PLANNING', 'DELETE_PROCUREMENT_ACQUISITION_PLANNING', 'CREATE_DOCUMENT', 'UPDATE_DOCUMENT', 'LOGIN_ATTEMPT', 'LOGOUT', 'GET_USER_DETAILS', 'CREATE_USER', 'UPDATE_USER', 'DEACTIVATE_USER'], | ||
[TableReference(table_schema='ops', table_name='ops_event', column_name='event_type'), TableReference(table_schema='ops', table_name='ops_event_version', column_name='event_type')], | ||
enum_values_to_rename=[]) | ||
# ### 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
from flask import Response, request | ||
from flask_jwt_extended import jwt_required | ||
|
||
from models import OpsEventType | ||
from ops_api.ops.auth.auth_types import Permission, PermissionType | ||
from ops_api.ops.auth.decorators import is_authorized | ||
from ops_api.ops.base_views import BaseItemAPI, BaseListAPI | ||
from ops_api.ops.schemas.cans import CreateUpdateFundingReceivedSchema, FundingReceivedSchema | ||
from ops_api.ops.services.can_funding_received import CANFundingReceivedService | ||
from ops_api.ops.utils.errors import error_simulator | ||
from ops_api.ops.utils.events import OpsEventHandler | ||
from ops_api.ops.utils.response import make_response_with_headers | ||
|
||
|
||
class CANFundingReceivedItemAPI(BaseItemAPI): | ||
def __init__(self, model): | ||
super().__init__(model) | ||
self.can_service = CANFundingReceivedService() | ||
|
||
@is_authorized(PermissionType.GET, Permission.CAN) | ||
def get(self, id: int) -> Response: | ||
schema = FundingReceivedSchema() | ||
item = self.can_service.get(id) | ||
return make_response_with_headers(schema.dump(item)) | ||
|
||
@is_authorized(PermissionType.PATCH, Permission.CAN) | ||
def patch(self, id: int) -> Response: | ||
""" | ||
Update a CANFundingReceived with only the fields provided in the request body. | ||
""" | ||
with OpsEventHandler(OpsEventType.UPDATE_CAN_FUNDING_RECEIVED) as meta: | ||
request_data = request.get_json() | ||
# Setting partial to true ignores any missing fields. | ||
schema = CreateUpdateFundingReceivedSchema(partial=True) | ||
serialized_request = schema.load(request_data) | ||
|
||
updated_funding_received = self.can_service.update(serialized_request, id) | ||
serialized_can_funding_received = schema.dump(updated_funding_received) | ||
meta.metadata.update({"updated_funding_received": serialized_can_funding_received}) | ||
return make_response_with_headers(serialized_can_funding_received) | ||
|
||
@is_authorized(PermissionType.PATCH, Permission.CAN) | ||
def put(self, id: int) -> Response: | ||
""" | ||
Update a CANFundingReceived | ||
""" | ||
with OpsEventHandler(OpsEventType.UPDATE_CAN_FUNDING_RECEIVED) as meta: | ||
request_data = request.get_json() | ||
schema = CreateUpdateFundingReceivedSchema() | ||
serialized_request = schema.load(request_data) | ||
|
||
updated_funding_received = self.can_service.update(serialized_request, id) | ||
serialized_funding_received = schema.dump(updated_funding_received) | ||
meta.metadata.update({"updated_can_funding_budget": serialized_funding_received}) | ||
return make_response_with_headers(serialized_funding_received) | ||
|
||
@is_authorized(PermissionType.DELETE, Permission.CAN) | ||
def delete(self, id: int) -> Response: | ||
""" | ||
Delete a CANFundingReceived with given id. | ||
""" | ||
with OpsEventHandler(OpsEventType.DELETE_CAN_FUNDING_RECEIVED) as meta: | ||
self.can_service.delete(id) | ||
meta.metadata.update({"Deleted CANFundingReceived": id}) | ||
return make_response_with_headers({"message": "CANFundingReceived deleted", "id": id}, 200) | ||
|
||
|
||
class CANFundingReceivedListAPI(BaseListAPI): | ||
def __init__(self, model): | ||
super().__init__(model) | ||
self.can_service = CANFundingReceivedService() | ||
|
||
@jwt_required() | ||
@error_simulator | ||
def get(self) -> Response: | ||
result = self.can_service.get_list() | ||
funding_received_schema = FundingReceivedSchema() | ||
return make_response_with_headers([funding_received_schema.dump(can) for can in result]) | ||
|
||
@is_authorized(PermissionType.POST, Permission.CAN) | ||
def post(self) -> Response: | ||
""" | ||
Create a new CANFundingReceived object | ||
""" | ||
with OpsEventHandler(OpsEventType.CREATE_CAN_FUNDING_RECEIVED) as meta: | ||
request_data = request.get_json() | ||
schema = CreateUpdateFundingReceivedSchema() | ||
serialized_request = schema.load(request_data) | ||
|
||
created_funding_received = self.can_service.create(serialized_request) | ||
|
||
funding_received_schema = FundingReceivedSchema() | ||
serialized_funding_received = funding_received_schema.dump(created_funding_received) | ||
meta.metadata.update({"new_can_funding_received": serialized_funding_received}) | ||
return make_response_with_headers(serialized_funding_received, 201) |
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.