"""Blueprint for Worksheet Corrections API.""" import simplejson as json from flask import Blueprint, request from owsresponse.adaptors.flask import flaskify from abacus_worksheet.logic.worksheet_correction import ( bulk_create, get_unapplied_worksheet_corrections, ) worksheet_correction_api = Blueprint( 'worksheet_correction_api', __name__, url_prefix='/worksheet-correction' ) @worksheet_correction_api.route('/bulk', methods=['POST']) def bulk_create_worksheet_corrections(): """POST one or more worksheet_correction records.""" parsed_body = json.loads(request.data.decode(), use_decimal=True) return flaskify(bulk_create(parsed_body)) @worksheet_correction_api.route( '/statement-period///unapplied', methods=['GET'], ) def get_unapplied_worksheet_corrections_by_statement_period_id( statement_period_id: int, correction_type: str ): """Get a list of unapplied worksheet corrections by statement_period_id and correction_type. Arg: statement_period_id (int): id of the statement period correction_type (str): either royalty_reversal or royalty_correction Returns: A list of unapplied worksheet corrections. """ correction_type = correction_type.replace('-', '_') return flaskify( get_unapplied_worksheet_corrections( statement_period_id, correction_type, request.args ) )