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
+23
View File
@@ -0,0 +1,23 @@
import { apiJson, withApiHandler } from "@/lib/api-handler";
import { createPlantForScope } from "@/modules/garden/server/actions";
import { plantInput } from "@/modules/garden/server/schemas";
import { getPlantForScope, listPlantsForScope } from "@/modules/garden/server/queries";
export async function GET(request: Request) {
return withApiHandler(request, async (scope, req) => {
const url = new URL(req.url);
const containerId = url.searchParams.get("containerId") ?? undefined;
const plants = await listPlantsForScope(scope.householdId, { containerId });
return apiJson(plants);
});
}
export async function POST(request: Request) {
return withApiHandler(request, async (scope, req) => {
const body: unknown = await req.json();
const parsed = plantInput.parse(body);
const plant = await createPlantForScope(scope, parsed);
const detail = await getPlantForScope(scope.householdId, plant.id);
return apiJson(detail, 201);
});
}