feat(fc2c-i): artist overview + paged images endpoints
This commit is contained in:
@@ -16,6 +16,7 @@ api_bp.add_url_rule("/health", view_func=health.get_health, methods=["GET"])
|
||||
def all_blueprints() -> list[Blueprint]:
|
||||
from .aliases import aliases_bp
|
||||
from .allowlist import allowlist_bp
|
||||
from .artist import artist_bp
|
||||
from .gallery import gallery_bp
|
||||
from .import_admin import import_admin_bp
|
||||
from .ml_admin import ml_admin_bp
|
||||
@@ -27,6 +28,7 @@ def all_blueprints() -> list[Blueprint]:
|
||||
api_bp,
|
||||
gallery_bp,
|
||||
tags_bp,
|
||||
artist_bp,
|
||||
showcase_bp,
|
||||
settings_bp,
|
||||
import_admin_bp,
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
"""Artist API: overview aggregates + paged images."""
|
||||
|
||||
from quart import Blueprint, jsonify, request
|
||||
|
||||
from ..extensions import get_session
|
||||
from ..services.artist_service import ArtistService
|
||||
|
||||
artist_bp = Blueprint("artist", __name__, url_prefix="/api/artist")
|
||||
|
||||
|
||||
@artist_bp.route("/<slug>", methods=["GET"])
|
||||
async def overview(slug: str):
|
||||
async with get_session() as session:
|
||||
svc = ArtistService(session)
|
||||
data = await svc.overview(slug)
|
||||
if data is None:
|
||||
return jsonify({"error": "artist not found"}), 404
|
||||
return jsonify(data)
|
||||
|
||||
|
||||
@artist_bp.route("/<slug>/images", methods=["GET"])
|
||||
async def images(slug: str):
|
||||
cursor = request.args.get("cursor") or None
|
||||
try:
|
||||
limit = int(request.args.get("limit", "60"))
|
||||
except ValueError:
|
||||
return jsonify({"error": "limit must be an integer"}), 400
|
||||
async with get_session() as session:
|
||||
svc = ArtistService(session)
|
||||
try:
|
||||
page = await svc.images(slug, cursor=cursor, limit=limit)
|
||||
except ValueError as exc:
|
||||
return jsonify({"error": str(exc)}), 400
|
||||
if page is None:
|
||||
return jsonify({"error": "artist not found"}), 404
|
||||
return jsonify({"images": page.images, "next_cursor": page.next_cursor})
|
||||
Reference in New Issue
Block a user