summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.claude/skills/update-band-info.md7
-rw-r--r--app/routes.ts2
-rw-r--r--app/routes/api-artist-detail.tsx51
-rw-r--r--app/routes/api-artists.tsx57
-rw-r--r--app/routes/api-band-detail.tsx71
-rw-r--r--app/routes/api-bands.tsx76
6 files changed, 121 insertions, 143 deletions
diff --git a/.claude/skills/update-band-info.md b/.claude/skills/update-band-info.md
index ebe80f7..f595362 100644
--- a/.claude/skills/update-band-info.md
+++ b/.claude/skills/update-band-info.md
@@ -37,7 +37,7 @@ print(json.dumps(matches, ensure_ascii=False, indent=2))
### Step 2: バンドの現在データを取得する
```bash
-curl -s "https://whoisband.yyamashita.com/api/bands/{uuid}"
+curl -s "https://whoisband.yyamashita.com/api/bands?id={uuid}"
```
レスポンスから以下を確認:
@@ -101,7 +101,7 @@ curl -s "https://whoisband.yyamashita.com/api/artists"
1. **SNS URL が一致** → 同一アーティストと断定
- 既存アーティストのリンク一覧と比較
- - `curl -s "https://whoisband.yyamashita.com/api/artists/{uuid}"` で各アーティストのリンクを確認
+ - `curl -s "https://whoisband.yyamashita.com/api/artists?id={uuid}"` で各アーティストのリンクを確認
2. **名前が完全一致** → 同一アーティストと断定
3. **名前が部分一致または表記ゆれ** → スキップ(あいまいな場合は追加しない)
4. **一致なし** → 新規アーティストとして登録
@@ -132,9 +132,10 @@ bio / 固定投稿 / プロフィール情報からパートを読み取る。
### Step 6: バンドを更新する
```bash
-curl -s -X PATCH "https://whoisband.yyamashita.com/api/bands/{uuid}" \
+curl -s -X PATCH "https://whoisband.yyamashita.com/api/bands" \
-H "Content-Type: application/json" \
-d '{
+ "id": "{uuid}",
"description": "SNSから取得した説明文",
"append_links": true,
"links": [
diff --git a/app/routes.ts b/app/routes.ts
index 518492f..0a2c028 100644
--- a/app/routes.ts
+++ b/app/routes.ts
@@ -3,9 +3,7 @@ import { type RouteConfig, index, route } from "@react-router/dev/routes";
export default [
index("routes/home.tsx"),
route("/api/bands", "routes/api-bands.tsx"),
- route("/api/bands/:uuid", "routes/api-band-detail.tsx"),
route("/api/artists", "routes/api-artists.tsx"),
- route("/api/artists/:uuid", "routes/api-artist-detail.tsx"),
route("/api/export", "routes/api-export.tsx"),
route("/api/import", "routes/api-import.tsx"),
route("/bands", "routes/band-index.tsx"),
diff --git a/app/routes/api-artist-detail.tsx b/app/routes/api-artist-detail.tsx
deleted file mode 100644
index 8328bca..0000000
--- a/app/routes/api-artist-detail.tsx
+++ /dev/null
@@ -1,51 +0,0 @@
-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));
-}
-
-export default function () { return null; }
diff --git a/app/routes/api-artists.tsx b/app/routes/api-artists.tsx
index 6f83bcc..930311d 100644
--- a/app/routes/api-artists.tsx
+++ b/app/routes/api-artists.tsx
@@ -1,15 +1,27 @@
-import type { ActionFunctionArgs } from "react-router";
-import { createArtist, getIpAddress, listArtists, toSlug } from "~/lib/db.server";
+import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";
+import {
+ createArtist,
+ getArtistById,
+ getArtistLinks,
+ getIpAddress,
+ listArtists,
+ toSlug,
+ updateArtist,
+} from "~/lib/db.server";
-export function loader() {
+export function loader({ request }: LoaderFunctionArgs) {
+ const url = new URL(request.url);
+ const id = url.searchParams.get("id");
+ if (id) {
+ const artist = getArtistById(id);
+ if (!artist) return Response.json({ error: "Not found" }, { status: 404 });
+ const links = getArtistLinks(artist.id);
+ return Response.json({ ...artist, links });
+ }
return Response.json(listArtists());
}
export async function action({ request }: ActionFunctionArgs) {
- if (request.method !== "POST") {
- return Response.json({ error: "Method not allowed" }, { status: 405 });
- }
-
let body: Record<string, unknown>;
try {
body = await request.json();
@@ -17,6 +29,36 @@ export async function action({ request }: ActionFunctionArgs) {
return Response.json({ error: "Invalid JSON body" }, { status: 400 });
}
+ if (request.method === "PATCH") {
+ const id = body.id as string | undefined;
+ if (!id) return Response.json({ error: "id is required" }, { status: 400 });
+ const artist = getArtistById(id);
+ if (!artist) return Response.json({ error: "Not found" }, { status: 404 });
+
+ 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));
+ }
+
+ if (request.method !== "POST") {
+ return Response.json({ error: "Method not allowed" }, { status: 405 });
+ }
+
const name = (body.name as string | undefined)?.trim();
if (!name) return Response.json({ error: "name is required" }, { status: 400 });
@@ -41,4 +83,3 @@ export async function action({ request }: ActionFunctionArgs) {
throw e;
}
}
-
diff --git a/app/routes/api-band-detail.tsx b/app/routes/api-band-detail.tsx
deleted file mode 100644
index 0cad372..0000000
--- a/app/routes/api-band-detail.tsx
+++ /dev/null
@@ -1,71 +0,0 @@
-import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";
-import {
- getBandById,
- getBandLinks,
- getBandMembers,
- getIpAddress,
- toSlug,
- updateBand,
- type MemberInput,
-} from "~/lib/db.server";
-
-export function loader({ params }: LoaderFunctionArgs) {
- const band = getBandById(params.uuid!);
- if (!band) return Response.json({ error: "Not found" }, { status: 404 });
- const links = getBandLinks(band.id);
- const members = getBandMembers(band.id);
- return Response.json({ ...band, links, members });
-}
-
-export async function action({ request, params }: ActionFunctionArgs) {
- if (request.method !== "PATCH") {
- return Response.json({ error: "Method not allowed" }, { status: 405 });
- }
-
- const band = getBandById(params.uuid!);
- if (!band) 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 = getBandLinks(band.id);
- const currentMembers = getBandMembers(band.id);
-
- const patchLinks = (body.links as { label: string; url: string }[] | undefined) ?? [];
- const patchMembers = (body.members as MemberInput[] | undefined) ?? [];
- const appendLinks = body.append_links !== false;
- const appendMembers = body.append_members !== 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;
-
- const existingArtistIds = new Set(currentMembers.map((m) => m.artist_id));
- const newMembers: MemberInput[] = appendMembers
- ? [
- ...currentMembers.map((m) => ({ artist_id: m.artist_id, role: m.role, since: m.since ?? "", until: m.until ?? "", note: m.note ?? "" })),
- ...patchMembers.filter((m) => !existingArtistIds.has(m.artist_id)),
- ]
- : patchMembers;
-
- updateBand(band.id, {
- slug: (body.slug as string | undefined) ?? band.slug,
- name: (body.name as string | undefined) ?? band.name,
- area: (body.area as string | undefined) ?? band.area,
- description: "description" in body ? (body.description as string | null) : band.description,
- status: (body.status as string | undefined) ?? band.status,
- links: newLinks,
- members: newMembers,
- message: (body.message as string | undefined) || "API update",
- ip_address: getIpAddress(request),
- });
-
- return Response.json(getBandById(band.id));
-}
-
-export default function () { return null; }
diff --git a/app/routes/api-bands.tsx b/app/routes/api-bands.tsx
index 1bcaae2..9fda52e 100644
--- a/app/routes/api-bands.tsx
+++ b/app/routes/api-bands.tsx
@@ -1,15 +1,30 @@
-import type { ActionFunctionArgs } from "react-router";
-import { createBand, getIpAddress, listBands, toSlug, type MemberInput } from "~/lib/db.server";
+import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";
+import {
+ createBand,
+ getBandById,
+ getBandLinks,
+ getBandMembers,
+ getIpAddress,
+ listBands,
+ toSlug,
+ updateBand,
+ type MemberInput,
+} from "~/lib/db.server";
-export function loader() {
+export function loader({ request }: LoaderFunctionArgs) {
+ const url = new URL(request.url);
+ const id = url.searchParams.get("id");
+ if (id) {
+ const band = getBandById(id);
+ if (!band) return Response.json({ error: "Not found" }, { status: 404 });
+ const links = getBandLinks(band.id);
+ const members = getBandMembers(band.id);
+ return Response.json({ ...band, links, members });
+ }
return Response.json(listBands());
}
export async function action({ request }: ActionFunctionArgs) {
- if (request.method !== "POST") {
- return Response.json({ error: "Method not allowed" }, { status: 405 });
- }
-
let body: Record<string, unknown>;
try {
body = await request.json();
@@ -17,6 +32,52 @@ export async function action({ request }: ActionFunctionArgs) {
return Response.json({ error: "Invalid JSON body" }, { status: 400 });
}
+ if (request.method === "PATCH") {
+ const id = body.id as string | undefined;
+ if (!id) return Response.json({ error: "id is required" }, { status: 400 });
+ const band = getBandById(id);
+ if (!band) return Response.json({ error: "Not found" }, { status: 404 });
+
+ const currentLinks = getBandLinks(band.id);
+ const currentMembers = getBandMembers(band.id);
+
+ const patchLinks = (body.links as { label: string; url: string }[] | undefined) ?? [];
+ const patchMembers = (body.members as MemberInput[] | undefined) ?? [];
+ const appendLinks = body.append_links !== false;
+ const appendMembers = body.append_members !== 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;
+
+ const existingArtistIds = new Set(currentMembers.map((m) => m.artist_id));
+ const newMembers: MemberInput[] = appendMembers
+ ? [
+ ...currentMembers.map((m) => ({ artist_id: m.artist_id, role: m.role, since: m.since ?? "", until: m.until ?? "", note: m.note ?? "" })),
+ ...patchMembers.filter((m) => !existingArtistIds.has(m.artist_id)),
+ ]
+ : patchMembers;
+
+ updateBand(band.id, {
+ slug: (body.slug as string | undefined) ?? band.slug,
+ name: (body.name as string | undefined) ?? band.name,
+ area: (body.area as string | undefined) ?? band.area,
+ description: "description" in body ? (body.description as string | null) : band.description,
+ status: (body.status as string | undefined) ?? band.status,
+ links: newLinks,
+ members: newMembers,
+ message: (body.message as string | undefined) || "API update",
+ ip_address: getIpAddress(request),
+ });
+
+ return Response.json(getBandById(band.id));
+ }
+
+ if (request.method !== "POST") {
+ return Response.json({ error: "Method not allowed" }, { status: 405 });
+ }
+
const name = (body.name as string | undefined)?.trim();
if (!name) return Response.json({ error: "name is required" }, { status: 400 });
@@ -45,4 +106,3 @@ export async function action({ request }: ActionFunctionArgs) {
throw e;
}
}
-