fc3f: GET /api/artists/directory — cursor + q + platform filters with validation
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
"""FC-3a: plural /api/artists endpoints — POST (find-or-create) +
|
||||
autocomplete. The slug-routed singular /api/artist/<slug> blueprint
|
||||
autocomplete. FC-3f: GET /api/artists/directory (cursor-paginated
|
||||
browse grid). The slug-routed singular /api/artist/<slug> blueprint
|
||||
stays separate and unmodified."""
|
||||
|
||||
from quart import Blueprint, jsonify, request
|
||||
|
||||
from ..extensions import get_session
|
||||
from ..services.artist_directory_service import ArtistDirectoryService
|
||||
from ..services.artist_service import ArtistService
|
||||
from ..services.source_service import KNOWN_PLATFORMS
|
||||
|
||||
artists_bp = Blueprint("artists", __name__, url_prefix="/api/artists")
|
||||
|
||||
@@ -42,3 +45,39 @@ async def autocomplete():
|
||||
return jsonify([
|
||||
{"id": a.id, "name": a.name, "slug": a.slug} for a in rows
|
||||
])
|
||||
|
||||
|
||||
@artists_bp.route("/directory", methods=["GET"])
|
||||
async def directory():
|
||||
"""FC-3f: cursor-paginated artists directory.
|
||||
|
||||
Mirrors /api/tags/directory shape: { cards: [...], next_cursor }.
|
||||
"""
|
||||
args = request.args
|
||||
|
||||
cursor = args.get("cursor") or None
|
||||
q = args.get("q") or None
|
||||
platform = args.get("platform") or None
|
||||
limit_raw = args.get("limit", "60")
|
||||
|
||||
try:
|
||||
limit = int(limit_raw)
|
||||
except ValueError:
|
||||
return jsonify({"error": "invalid_limit"}), 400
|
||||
if limit < 1 or limit > 200:
|
||||
return jsonify({"error": "invalid_limit"}), 400
|
||||
|
||||
if platform is not None and platform not in KNOWN_PLATFORMS:
|
||||
return jsonify({"error": "unknown_platform"}), 400
|
||||
|
||||
async with get_session() as session:
|
||||
svc = ArtistDirectoryService(session)
|
||||
try:
|
||||
page = await svc.list_artists(
|
||||
q=q, platform=platform, cursor=cursor, limit=limit,
|
||||
)
|
||||
except ValueError:
|
||||
# Service raises only on bad cursor (limit was validated above).
|
||||
return jsonify({"error": "invalid_cursor"}), 400
|
||||
|
||||
return jsonify({"cards": page.cards, "next_cursor": page.next_cursor})
|
||||
|
||||
Reference in New Issue
Block a user