summaryrefslogtreecommitdiff
path: root/app/routes/api.events.$id.ts
diff options
context:
space:
mode:
Diffstat (limited to 'app/routes/api.events.$id.ts')
-rw-r--r--app/routes/api.events.$id.ts22
1 files changed, 22 insertions, 0 deletions
diff --git a/app/routes/api.events.$id.ts b/app/routes/api.events.$id.ts
new file mode 100644
index 0000000..0f0f2e8
--- /dev/null
+++ b/app/routes/api.events.$id.ts
@@ -0,0 +1,22 @@
+/**
+ * GET /api/events/:id
+ */
+import type { Route } from "./+types/api.events.$id";
+import { getEvent } from "~/lib/db.server";
+
+export async function loader({ params }: Route.LoaderArgs) {
+ const id = parseInt(params.id, 10);
+ if (Number.isNaN(id)) {
+ return Response.json({ error: "Invalid id" }, { status: 400 });
+ }
+
+ const event = getEvent(id);
+ if (!event) {
+ return Response.json({ error: "Not found" }, { status: 404 });
+ }
+
+ return Response.json(
+ { event },
+ { headers: { "Cache-Control": "public, max-age=300" } }
+ );
+}