From 2f15efe21e9c6bb0e264b2ef2f30011123e0c016 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Oudelet?= Date: Wed, 22 Apr 2026 14:28:03 +0200 Subject: [PATCH] =?UTF-8?q?PMPR-33=20:=20POST=20/ues=20-=20cr=C3=A9er=20un?= =?UTF-8?q?e=20UE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routes/(apps)/notes/api/ues.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/routes/(apps)/notes/api/ues.ts b/routes/(apps)/notes/api/ues.ts index 562ca90..19b7d51 100644 --- a/routes/(apps)/notes/api/ues.ts +++ b/routes/(apps)/notes/api/ues.ts @@ -3,6 +3,7 @@ import { db } from "../../../../databases/db.ts"; import { ues } from "../../../../databases/schema.ts"; export const handler: Handlers = { + // #32 GET /ues async GET() { try { const result = await db.select().from(ues); @@ -16,4 +17,26 @@ export const handler: Handlers = { return new Response("Failed to fetch data", { status: 500 }); } }, + + // #33 POST /ues + async POST(request) { + try { + const body = await request.json(); + const { nom } = body; + + if (!nom) { + return new Response("Champ 'nom' manquant", { status: 400 }); + } + + const result = await db.insert(ues).values({ nom }).returning(); + + return new Response(JSON.stringify(result[0]), { + status: 201, + headers: { "Content-Type": "application/json" }, + }); + } catch (error) { + console.error("Error creating UE:", error); + return new Response("Failed to create UE", { status: 500 }); + } + }, }; \ No newline at end of file -- 2.52.0