import { Handlers } from "$fresh/server.ts"; 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); return new Response(JSON.stringify(result), { status: 200, headers: { "Content-Type": "application/json" }, }); } catch (error) { console.error("Error fetching UEs:", error); 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 }); } }, };