feat: artist item API — detail, auto-monitor toggle, unfollow

This commit is contained in:
Jonathan
2026-07-11 13:55:36 +02:00
parent 7f0ac68657
commit 1e39c74b16
2 changed files with 117 additions and 0 deletions
+57
View File
@@ -0,0 +1,57 @@
import { prisma } from "@/lib/db";
export async function GET(_request: Request, { params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
const artist = await prisma.watchedArtist.findUnique({
where: { id },
include: { releases: { orderBy: [{ firstReleaseDate: "desc" }, { album: "asc" }] } },
});
if (!artist) return Response.json({ error: "not found" }, { status: 404 });
return Response.json({
id: artist.id,
mbid: artist.mbid,
name: artist.name,
autoMonitorFuture: artist.autoMonitorFuture,
releases: artist.releases.map((r) => ({
id: r.id,
rgMbid: r.rgMbid,
album: r.album,
primaryType: r.primaryType,
secondaryTypes: r.secondaryTypes,
firstReleaseDate: r.firstReleaseDate,
monitored: r.monitored,
state: r.state,
currentQualityClass: r.currentQualityClass,
})),
});
}
export async function PATCH(request: Request, { params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
let body: unknown;
try {
body = await request.json();
} catch {
return Response.json({ error: "invalid JSON" }, { status: 400 });
}
const { autoMonitorFuture } = (body ?? {}) as { autoMonitorFuture?: unknown };
if (typeof autoMonitorFuture !== "boolean") {
return Response.json({ error: "autoMonitorFuture (boolean) is required" }, { status: 400 });
}
try {
const updated = await prisma.watchedArtist.update({ where: { id }, data: { autoMonitorFuture } });
return Response.json({ id: updated.id, autoMonitorFuture: updated.autoMonitorFuture });
} catch {
return Response.json({ error: "not found" }, { status: 404 });
}
}
export async function DELETE(_request: Request, { params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
try {
await prisma.watchedArtist.delete({ where: { id } });
return new Response(null, { status: 204 });
} catch {
return Response.json({ error: "not found" }, { status: 404 });
}
}