feat: api v1 garden bangs routes and openapi

This commit is contained in:
ginnoir
2026-07-04 19:13:49 -05:00
parent d4304b005c
commit e8d13bede8
16 changed files with 1351 additions and 113 deletions
@@ -0,0 +1,36 @@
import { apiJson, withApiHandler } from "@/lib/api-handler";
import { deletePlantForScope, updatePlantForScope } from "@/modules/garden/server/actions";
import { plantUpdateInput } from "@/modules/garden/server/schemas";
import { getPlantForScope } from "@/modules/garden/server/queries";
import { z } from "zod";
export async function GET(request: Request, { params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
return withApiHandler(request, async (scope) => {
z.string().uuid().parse(id);
const plant = await getPlantForScope(scope.householdId, id);
if (!plant) throw new Error("Plant not found");
return apiJson(plant);
});
}
export async function PATCH(request: Request, { params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
return withApiHandler(request, async (scope, req) => {
const body: unknown = await req.json();
const parsed = plantUpdateInput.parse(body);
await updatePlantForScope(scope, { id, ...parsed });
const plant = await getPlantForScope(scope.householdId, id);
if (!plant) throw new Error("Plant not found");
return apiJson(plant);
});
}
export async function DELETE(request: Request, { params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
return withApiHandler(request, async (scope) => {
z.string().uuid().parse(id);
await deletePlantForScope(scope, { id });
return apiJson({ ok: true });
});
}