"""Service handlers.""" from flask import g, request from owsrequest.flask_request import request_context_from_headers from owsresponse.adaptors.flask import flaskify from participant.api import app from participant.logic import artist_links @app.route('/artist-links', methods=['GET']) @request_context_from_headers() def get_artist_links(): """Get the artist links table info. Returns: flask.Response: All artist links for label/subaccount """ vendor_id, subaccount_id = _vendor_and_subaccount_id() return flaskify(artist_links.get_artist_links(vendor_id, subaccount_id)) @app.route('/artist-links', methods=['POST']) @request_context_from_headers() def update_artist_links(): """Update the artist links table info. Returns: flask.Response: All artist links for label/subaccount """ data = request.get_json() vendor_id, subaccount_id = _vendor_and_subaccount_id() return flaskify(artist_links.update_artist_links(vendor_id, subaccount_id, data)) def _vendor_and_subaccount_id(): vendor_id = 0 subaccount_id = 0 if g.request_context.profile_type == 'vendor': vendor_id = int(g.request_context.profile_id) else: subaccount_id = int(g.request_context.profile_id) return [vendor_id, subaccount_id]