From 82eda9e3531bb06ebec4f93c353b62641032d2d8 Mon Sep 17 00:00:00 2001 From: redglow Date: Sun, 21 Jun 2026 16:21:55 +0200 Subject: [PATCH] feat: add /announcements/from-game endpoint --- src/server/main.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/server/main.ts b/src/server/main.ts index bcdab3f..49848fc 100644 --- a/src/server/main.ts +++ b/src/server/main.ts @@ -41,6 +41,10 @@ const AnnouncementIdInput = z.object({ announcementId: z.coerce.number().positive(), }); +const GetFromGame = z.object({ + gameName: z.string().nonempty(), +}); + app.get("/api/announcements", async (_, res) => { const announcements = await db .selectFrom("announcements") @@ -50,6 +54,18 @@ app.get("/api/announcements", async (_, res) => { res.json(announcements); }); +app.get("/api/announcements/from-game", async (req, res) => { + const fromGameData = GetFromGame.parse(req.query); + console.log(`Request from game ${fromGameData.gameName}`); + const announcements = await db + .selectFrom("announcements") + .select(["id", "title", "text", "publication_date", "image"]) + .orderBy("announcements.publication_date", "desc") + .limit(3) + .execute(); + res.json(announcements); +}); + app.get("/api/announcements/:announcementId", async (req, res) => { const { announcementId } = AnnouncementIdInput.parse(req.params); const announcement = await db