From 33d023986c34dac92371baa46e489e095110af09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Oudelet?= Date: Wed, 22 Apr 2026 18:26:45 +0200 Subject: [PATCH] =?UTF-8?q?PMPR-34=20:=20GET=20/ues/{idUE}=20-=20r=C3=A9cu?= =?UTF-8?q?p=C3=A9rer=20une=20UE=20par=20son=20id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routes/(apps)/notes/api/ues/[idUE].ts | 37 +++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 routes/(apps)/notes/api/ues/[idUE].ts diff --git a/routes/(apps)/notes/api/ues/[idUE].ts b/routes/(apps)/notes/api/ues/[idUE].ts new file mode 100644 index 0000000..9fb70fa --- /dev/null +++ b/routes/(apps)/notes/api/ues/[idUE].ts @@ -0,0 +1,37 @@ +import { Handlers } from "$fresh/server.ts"; +import { db } from "../../../../../databases/db.ts"; +import { ues } from "../../../../../databases/schema.ts"; +import { eq } from "npm:drizzle-orm"; + +export const handler: Handlers = { + // # 34 GET /ues/:idUE + async GET(_request, context) { + try { + const idUE = parseInt(context.params.idUE); + + if (isNaN(idUE)) { + return new Response(JSON.stringify({ error: "Paramètre idUE invalide" }), { + status: 400, + headers: { "Content-Type": "application/json" }, + }); + } + + const result = await db.select().from(ues).where(eq(ues.id, idUE)); + + if (result.length === 0) { + return new Response(JSON.stringify({ error: "Ressource introuvable" }), { + status: 404, + headers: { "Content-Type": "application/json" }, + }); + } + + return new Response(JSON.stringify(result[0]), { + status: 200, + headers: { "Content-Type": "application/json" }, + }); + } catch (error) { + console.error("Error fetching UE:", error); + return new Response("Failed to fetch data", { status: 500 }); + } + }, +}; \ No newline at end of file -- 2.52.0