"""Blueprint for WorksheetPaymentCustom API.""" from http import HTTPStatus from abacus_common_logic.marshalling.base import PaginationSchema from common_apispec import doc, marshal_with, use_kwargs from flask import Blueprint, Response from payment.logic import worksheet_payment_custom as logic from payment.schemas.worksheet_payment_custom import ( WorksheetPaymentCustomDetailSchema, WorksheetPaymentCustomFilterParamsPostSchema, WorksheetPaymentCustomListSchema, WorksheetPaymentCustomPostSchema, ) from payment.utils.authorization import check_access worksheet_payment_custom_api = Blueprint('worksheet_payment_custom_api', __name__) @worksheet_payment_custom_api.route('/payment/custom', methods=['POST']) @doc( tags=['worksheet payment custom'], description='Create a new WorksheetPaymentCustom record.', ) @check_access @use_kwargs(WorksheetPaymentCustomPostSchema, location='json') @marshal_with( WorksheetPaymentCustomDetailSchema, code=HTTPStatus.CREATED, description=HTTPStatus.CREATED.phrase, ) def create_worksheet_payment_custom(**params) -> Response: """POST WorksheetPaymentCustom.""" result = logic.create_worksheet_payment_custom(**params) return result, HTTPStatus.CREATED @worksheet_payment_custom_api.route('/payments/custom/bulk', methods=['POST']) @doc( tags=['worksheet payment custom'], description='Get a list of WorksheetPaymentCustom records.', ) @check_access @use_kwargs(PaginationSchema, location='query') @use_kwargs(WorksheetPaymentCustomFilterParamsPostSchema, location='json') @marshal_with( WorksheetPaymentCustomListSchema, code=HTTPStatus.OK, description=HTTPStatus.OK.phrase, ) def get_worksheet_payment_custom_list(**payload) -> Response: """GET WorksheetPaymentCustom list.""" filters = payload.pop('filters', {}) worksheet_payment_custom_ids = filters.get('worksheet_payment_custom_ids') response = logic.get_worksheet_payment_custom_list( worksheet_payment_custom_ids=worksheet_payment_custom_ids, **payload ) return response, HTTPStatus.OK @worksheet_payment_custom_api.route( '/payment/custom/', methods=['GET'] ) @doc( tags=['worksheet payment custom'], description='Get a single WorksheetPaymentCustom record by ID.', ) @check_access @marshal_with( WorksheetPaymentCustomDetailSchema, code=HTTPStatus.OK, description=HTTPStatus.OK.phrase, ) def get_worksheet_payment_custom(worksheet_payment_custom_id: int) -> Response: """GET WorksheetPaymentCustom by ID.""" result = logic.get_worksheet_payment_custom_by_id(worksheet_payment_custom_id) return result, HTTPStatus.OK @worksheet_payment_custom_api.route( '/payment/custom/', methods=['DELETE'] ) @doc( tags=['worksheet payment custom'], description='Delete a WorksheetPaymentCustom record by ID.', ) @check_access @marshal_with( None, code=HTTPStatus.NO_CONTENT, description=HTTPStatus.NO_CONTENT.phrase, apply=False, ) @marshal_with( None, code=HTTPStatus.BAD_REQUEST, description=HTTPStatus.BAD_REQUEST.phrase, ) def delete_worksheet_payment_custom( worksheet_payment_custom_id: int, ) -> Response: """DELETE WorksheetPaymentCustom by ID.""" logic.delete_worksheet_payment_custom(worksheet_payment_custom_id) return None, HTTPStatus.NO_CONTENT