From 96b7edf77f606cc0f95cc00ffcc68cca682d5798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Oudelet?= Date: Wed, 22 Apr 2026 18:01:35 +0200 Subject: [PATCH] =?UTF-8?q?PMPR-43=20:=20POST=20/notes=20-=20cr=C3=A9er=20?= =?UTF-8?q?une=20note?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routes/(apps)/notes/api/notes.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/routes/(apps)/notes/api/notes.ts b/routes/(apps)/notes/api/notes.ts index 385caaa..0dcdf39 100644 --- a/routes/(apps)/notes/api/notes.ts +++ b/routes/(apps)/notes/api/notes.ts @@ -36,4 +36,26 @@ export const handler: Handlers = { return new Response("Failed to fetch data", { status: 500 }); } }, + + // #43 POST /notes + async POST(request) { + try { + const body = await request.json(); + const { note, numEtud, idModule } = body; + + if (note === undefined || !numEtud || !idModule) { + return new Response("Champs 'note', 'numEtud' et 'idModule' requis", { status: 400 }); + } + + const result = await db.insert(notes).values({ note, numEtud, idModule }).returning(); + + return new Response(JSON.stringify(result[0]), { + status: 201, + headers: { "Content-Type": "application/json" }, + }); + } catch (error) { + console.error("Error creating note:", error); + return new Response("Failed to create note", { status: 500 }); + } + }, }; \ No newline at end of file -- 2.52.0