import { NextResponse } from "next/server"; import { authenticateRequest, handleApiError } from "@/lib/api/authenticate"; import { animalCreateInput } from "@/lib/api/schemas"; import { listAnimals, createAnimal } from "@/lib/services/animals"; // GET /api/v1/animals?q=&species= export async function GET(req: Request) { try { const ctx = await authenticateRequest(req, "animals:read"); const sp = new URL(req.url).searchParams; return NextResponse.json( await listAnimals(ctx, { q: sp.get("q") ?? undefined, species: sp.get("species") ?? undefined }), ); } catch (err) { return handleApiError(err); } } // POST /api/v1/animals export async function POST(req: Request) { try { const ctx = await authenticateRequest(req, "animals:write"); const input = animalCreateInput.parse(await req.json()); return NextResponse.json(await createAnimal(ctx, input), { status: 201 }); } catch (err) { return handleApiError(err); } }