def images_search(): params = { param: request.args[param] for param in request.args if param in ['title', 'year', 'artist_name', 'description', 'genre', 'max_items', 'order'] } if not params: return bad_request("at least one parameter is required for search function") query_result, error = Image.filter_by_params(params) if error: return error data = [image.to_json_search_result for image in query_result] return ok_response(data, **params)
def artists_list_get(): order = request.args.get('order', 'asc') count = request.args.get('count', None, type=int) artists_query, error = Artist.filter_by_order(Artist.query, order) if error: return error artists = artists_query.all() if count: artists = artists[:count] data = [artist.to_json_with_detail for artist in artists] return ok_response(data)
def images_list_get(): order = request.args.get('order', 'asc') count = request.args.get('count', None, type=int) images_query, error = Image.filter_by_order(Image.query, order) if error: return error images = images_query.all() if count: images = images[:count] data = [image.to_json_with_detail for image in images] return ok_response(data)
def artists_search(): params = { param: request.args[param] for param in request.args if param in ['name', 'country', 'genre', 'alive_in', 'max_items', 'order'] } if not params: return bad_request("at least one parameter is required for search function") query_result, error = Artist.filter_by_params(params) if error: return error data = [artist.to_json_with_detail for artist in query_result] return ok_response(data, **params)
def artists_search(): params = { param: request.args[param] for param in request.args if param in ['name', 'country', 'genre', 'alive_in', 'max_items', 'order'] } if not params: return bad_request( "at least one parameter is required for search function") query_result, error = Artist.filter_by_params(params) if error: return error data = [artist.to_json_with_detail for artist in query_result] return ok_response(data, **params)
def artists_detail(artist_id): artist = Artist.query.get(artist_id) if artist: return ok_response(artist.to_json_with_artworks) return not_found("URL path invalid, check artist_id")
def artists_artworks(artist_id): artist = Artist.query.get(artist_id) if artist: data = [image.to_json_with_detail for image in artist.images] return ok_response(data) return not_found("URL path invalid, check artist_id")
def images_detail(image_id): image = Image.query.get(image_id) if image: return ok_response(image.to_json_with_artist) return not_found("URL path invalid, check image_id")