feat: artist item API — detail, auto-monitor toggle, unfollow
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user