import { z } from "zod"; import { apiError, readJson, withApi } from "@/lib/api"; import { addTitle, getUniverse } from "@/lib/universes"; /** GET /api/v1/universen/{id}?reihenfolge=… — Inhalt und Fortschritt. */ export const GET = withApi(async (request, user, context) => { const { id } = await context.params; if (!id) return apiError("Es fehlt die Kennung des Universums.", 400); const url = new URL(request.url); const universe = await getUniverse(user.id, id, url.searchParams.get("reihenfolge") ?? undefined); if (!universe) return apiError("Dieses Universum gibt es nicht.", 404); return universe; }); const addSchema = z.object({ titleId: z.string().min(1) }); /** POST /api/v1/universen/{id} — Titel aufnehmen. */ export const POST = withApi(async (request, user, context) => { const { id } = await context.params; if (!id) return apiError("Es fehlt die Kennung des Universums.", 400); const body = await readJson(request, addSchema); await addTitle(user.id, id, body.titleId); return { ok: true }; });