diff options
| author | yyamashita <yyamashita@mosquit.one> | 2026-05-15 00:16:27 +0900 |
|---|---|---|
| committer | yyamashita <yyamashita@mosquit.one> | 2026-05-15 00:16:27 +0900 |
| commit | b29876cf6f865182ef6958aaf63d91d43dd08d55 (patch) | |
| tree | 381808b8593febbde5abdcb320d7eba8915faa65 /app/routes/api-artist-detail.tsx | |
| parent | 1a8a159a71fd018bab0e14d9df952c53ae5ea062 (diff) | |
Fix nav classes, add detail APIs, add update-band-info skill
- Fix nav: apply .nav class and .nav-brand to logo (styles were not rendering)
- Add GET+PATCH /api/bands/:uuid and /api/artists/:uuid endpoints
- PATCH supports append_links / append_members for non-destructive updates
- Add /update-band-info skill: fetch SNS profiles and update band description/members
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'app/routes/api-artist-detail.tsx')
| -rw-r--r-- | app/routes/api-artist-detail.tsx | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/app/routes/api-artist-detail.tsx b/app/routes/api-artist-detail.tsx new file mode 100644 index 0000000..1d874ad --- /dev/null +++ b/app/routes/api-artist-detail.tsx @@ -0,0 +1,49 @@ +import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router"; +import { + getArtistById, + getArtistLinks, + getIpAddress, + updateArtist, +} from "~/lib/db.server"; + +export function loader({ params }: LoaderFunctionArgs) { + const artist = getArtistById(params.uuid!); + if (!artist) return Response.json({ error: "Not found" }, { status: 404 }); + const links = getArtistLinks(artist.id); + return Response.json({ ...artist, links }); +} + +export async function action({ request, params }: ActionFunctionArgs) { + if (request.method !== "PATCH") { + return Response.json({ error: "Method not allowed" }, { status: 405 }); + } + + const artist = getArtistById(params.uuid!); + if (!artist) return Response.json({ error: "Not found" }, { status: 404 }); + + let body: Record<string, unknown>; + try { + body = await request.json(); + } catch { + return Response.json({ error: "Invalid JSON body" }, { status: 400 }); + } + + const currentLinks = getArtistLinks(artist.id); + const patchLinks = (body.links as { label: string; url: string }[] | undefined) ?? []; + const appendLinks = body.append_links !== false; + + const existingUrls = new Set(currentLinks.map((l) => l.url)); + const newLinks = appendLinks + ? [...currentLinks.map((l) => ({ label: l.label, url: l.url })), ...patchLinks.filter((l) => !existingUrls.has(l.url))] + : patchLinks; + + updateArtist(artist.id, { + slug: (body.slug as string | undefined) ?? artist.slug, + name: (body.name as string | undefined) ?? artist.name, + links: newLinks, + message: (body.message as string | undefined) || "API update", + ip_address: getIpAddress(request), + }); + + return Response.json(getArtistById(artist.id)); +} |
