"""Product Handlers.""" from flask import request from marshmallow import ValidationError from owsresponse import response from owsresponse.adaptors.flask import flaskify from participant.api import app from participant.constants import error from participant.logic import label_participant from participant.schemas.input.search_label_participant_by_product import ( SearchLabelParticipantByProductSchema, ) from participant.utils import json_encoder @app.route('/products//participants', methods=['GET']) @app.route('/products//label-participants', methods=['GET']) def find_label_participant_by_product_id(product_id): """Find Label Participant by associated Product id.""" vendor_id = request.args.get('vendor_id') subaccount_id = request.args.get('subaccount_id') params = dict( product_id=product_id, vendor_id=vendor_id, subaccount_id=subaccount_id ) try: SearchLabelParticipantByProductSchema().load(params) except ValidationError as err: return flaskify( response.create_error_response( code=error.ERROR_CODE_INVALID_USAGE, message=err.messages ) ) return flaskify( label_participant.get_label_participants_by_related_product_id( product_id, int(vendor_id), int(subaccount_id) ), encoder=json_encoder.JSONNeo4jEncoder, )