"""Reference Transaction Type handlers.""" from abacus_common_logic.views.list_view import ListView from flask import Blueprint, request from owsrequest import flask_request from owsresponse import response from owsresponse.adaptors.flask import flaskify from abacus_contract.constants.error import ( ERROR_CODE_FORBIDDEN, ERROR_MESSAGE_FORBIDDEN_USER, ) from abacus_contract.models import ReferenceTransactionType from abacus_contract.schemas.reference_transaction_type import ( ReferenceTransactionTypeSchema, ) from abacus_contract.utils.authorization import pdp_authorize_resource from core.cache import cache_reference_data reference_transaction_type_api = Blueprint('reference_transaction_type_api', __name__) class ReferenceTransactionTypeList(ListView): """View for listing reference_transaction_types.""" model_class = ReferenceTransactionType list_entry_schema = ReferenceTransactionTypeSchema() @cache_reference_data def get(self): """GET list of reference_transaction_types.""" access_rule_decision = flask_request.verify_rules_access_standalone(request) if not access_rule_decision: authorized = pdp_authorize_resource( resource_id=0, resource_type='reference_transaction_type', action='view' ) if not authorized: return flaskify( response.create_error_response( code=ERROR_CODE_FORBIDDEN, message=ERROR_MESSAGE_FORBIDDEN_USER, status=403, ) ) transaction_types = ReferenceTransactionType.get_all() return flaskify( response.Response( message=ReferenceTransactionTypeSchema(many=True).dump( transaction_types ), status=200, ) ) reference_transaction_type_api.add_url_rule( '/reference-transaction-types', methods=['GET'], view_func=ReferenceTransactionTypeList.as_view('reference_transaction_types'), )