2026-08-25 07:51:38 +02:00
|
|
|
import { NextResponse } from "next/server";
|
|
|
|
|
import { z } from "zod";
|
|
|
|
|
import { deleteRecording, getRecording, renameRecording } from "@/lib/db/queries/recordings";
|
2026-08-26 08:45:15 +02:00
|
|
|
import { withRouteLogging } from "@/lib/api/with-route-logging";
|
2026-08-25 07:51:38 +02:00
|
|
|
|
|
|
|
|
const patchSchema = z.object({
|
|
|
|
|
name: z.string().min(1).max(160).optional(),
|
|
|
|
|
description: z.string().max(2000).optional(),
|
|
|
|
|
});
|
|
|
|
|
|
2026-08-26 08:45:15 +02:00
|
|
|
export const GET = withRouteLogging(
|
|
|
|
|
"recordings.get",
|
|
|
|
|
async (_req: Request, { params }: { params: Promise<{ id: string }> }) => {
|
|
|
|
|
const { id } = await params;
|
|
|
|
|
const result = await getRecording(Number(id));
|
|
|
|
|
if (!result) return NextResponse.json({ error: "not found" }, { status: 404 });
|
|
|
|
|
return NextResponse.json(result);
|
|
|
|
|
},
|
|
|
|
|
);
|
2026-08-25 07:51:38 +02:00
|
|
|
|
2026-08-26 08:45:15 +02:00
|
|
|
export const PATCH = withRouteLogging(
|
|
|
|
|
"recordings.update",
|
|
|
|
|
async (req: Request, { params }: { params: Promise<{ id: string }> }) => {
|
|
|
|
|
const { id } = await params;
|
|
|
|
|
const parsed = patchSchema.safeParse(await req.json().catch(() => null));
|
|
|
|
|
if (!parsed.success) {
|
|
|
|
|
return NextResponse.json({ error: "invalid body" }, { status: 400 });
|
|
|
|
|
}
|
|
|
|
|
const updated = await renameRecording(Number(id), parsed.data);
|
|
|
|
|
if (!updated) return NextResponse.json({ error: "not found" }, { status: 404 });
|
|
|
|
|
return NextResponse.json({ recording: updated });
|
|
|
|
|
},
|
|
|
|
|
);
|
2026-08-25 07:51:38 +02:00
|
|
|
|
2026-08-26 08:45:15 +02:00
|
|
|
export const DELETE = withRouteLogging(
|
|
|
|
|
"recordings.delete",
|
|
|
|
|
async (_req: Request, { params }: { params: Promise<{ id: string }> }) => {
|
|
|
|
|
const { id } = await params;
|
|
|
|
|
await deleteRecording(Number(id));
|
|
|
|
|
return NextResponse.json({ ok: true });
|
|
|
|
|
},
|
|
|
|
|
);
|