CI / lint (push) Successful in 2s
CI / extension-version (push) Successful in 2s
Build images / sign-extension (push) Successful in 3s
Build images / build-agent (push) Successful in 6s
CI / frontend-build (push) Successful in 21s
CI / backend-lint-and-test (push) Successful in 33s
Build images / build-web (push) Successful in 1m2s
Build images / smoke-web (push) Skipped
Build images / build-ml (push) Successful in 1m54s
Build images / promote (push) Skipped
CI / integration (push) Successful in 2m20s
Operator: "the filters in the latest feed, drop down but don't have values". Two separate causes: - Platform: PostsFilterBar built its items from `platformsStore.platforms`. The platforms store has never had that property; it exposes `list` and `byKey`. The read returned undefined, `|| []` turned that into an empty list, and nothing failed. ArtistsView had copied the same read, so the Browse → Artists platform filter was empty too. Both now read `list` and show platform names rather than raw keys. - Artist: the autocomplete searched the server only after something was typed (autocomplete returns [] for an empty query by design, which its tests pin). Opening the dropdown therefore showed an empty menu. PostsFilterBar now loads every artist once from a new lightweight `GET /api/artists/names` (id, name, slug; alphabetical; no joins) and filters client-side, so the list is there on open. A deep-linked artist_id now also shows the artist's real name instead of "Artist #id". Guard: frontend/test/storeUsage.spec.js scans src for `platformsStore.<name>` and fails on any name the store doesn't define, since the frontend CI has no type-checker to catch this. A positive control shows the shipped `platformsStore.platforms` read is flagged, and a vacuity check confirms the scan really walks the tree. tests/test_api_artists_create.py covers /names. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SHQB1YukL3VyvMK8rcbmV9
112 lines
4.1 KiB
Python
112 lines
4.1 KiB
Python
"""FC-3a: plural /api/artists endpoints — POST (find-or-create) +
|
|
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")
|
|
|
|
|
|
@artists_bp.route("", methods=["POST"])
|
|
async def create_or_get():
|
|
body = await request.get_json()
|
|
if not isinstance(body, dict):
|
|
return jsonify({"error": "invalid_body"}), 400
|
|
name = body.get("name", "")
|
|
async with get_session() as session:
|
|
svc = ArtistService(session)
|
|
try:
|
|
artist, created = await svc.find_or_create(name)
|
|
except ValueError as exc:
|
|
return jsonify({"error": "empty_name", "detail": str(exc)}), 400
|
|
return jsonify({
|
|
"id": artist.id, "name": artist.name, "slug": artist.slug,
|
|
"created": created,
|
|
}), 201
|
|
|
|
|
|
@artists_bp.route("/<int:artist_id>", methods=["PATCH"])
|
|
async def rename(artist_id: int):
|
|
"""Rename an artist's DISPLAY NAME (#130). Name only — the slug and every
|
|
on-disk path stay put, so this is instant and safe. Name is non-unique."""
|
|
body = await request.get_json()
|
|
if not isinstance(body, dict) or not isinstance(body.get("name"), str):
|
|
return jsonify({"error": "invalid_body"}), 400
|
|
async with get_session() as session:
|
|
svc = ArtistService(session)
|
|
try:
|
|
artist = await svc.rename(artist_id, body["name"])
|
|
except ValueError as exc:
|
|
return jsonify({"error": "empty_name", "detail": str(exc)}), 400
|
|
if artist is None:
|
|
return jsonify({"error": "not_found"}), 404
|
|
return jsonify({"id": artist.id, "name": artist.name, "slug": artist.slug})
|
|
|
|
|
|
@artists_bp.route("/autocomplete", methods=["GET"])
|
|
async def autocomplete():
|
|
q = request.args.get("q") or ""
|
|
try:
|
|
limit = int(request.args.get("limit", "20"))
|
|
except ValueError:
|
|
return jsonify({"error": "invalid_limit"}), 400
|
|
if limit < 1 or limit > 100:
|
|
return jsonify({"error": "invalid_limit"}), 400
|
|
async with get_session() as session:
|
|
rows = await ArtistService(session).autocomplete(q, limit=limit)
|
|
return jsonify([
|
|
{"id": a.id, "name": a.name, "slug": a.slug} for a in rows
|
|
])
|
|
|
|
|
|
@artists_bp.route("/names", methods=["GET"])
|
|
async def names():
|
|
"""Every artist, id + name + slug, alphabetical. For filter pickers that
|
|
list artists before anything is typed; `autocomplete` deliberately returns
|
|
nothing for an empty query."""
|
|
async with get_session() as session:
|
|
rows = await ArtistService(session).all_names()
|
|
return jsonify([{"id": i, "name": n, "slug": s} for i, n, s 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})
|