route.ts 571 B

123456789101112131415161718192021222324
  1. import { getWidgets, createWidget } from "@/lib/db/store";
  2. export async function GET() {
  3. const widgetList = await getWidgets();
  4. return Response.json({ data: widgetList, total: widgetList.length });
  5. }
  6. export async function POST(req: Request) {
  7. const body = await req.json();
  8. if (!body.prompt || !body.spec) {
  9. return Response.json(
  10. { error: "prompt and spec are required" },
  11. { status: 400 },
  12. );
  13. }
  14. const widget = await createWidget({
  15. prompt: body.prompt,
  16. spec: body.spec,
  17. });
  18. return Response.json(widget, { status: 201 });
  19. }