feat: add /announcements/from-game endpoint

This commit is contained in:
redglow
2026-06-21 16:21:55 +02:00
parent 0dd783f751
commit 82eda9e353
+16
View File
@@ -41,6 +41,10 @@ const AnnouncementIdInput = z.object({
announcementId: z.coerce.number().positive(), announcementId: z.coerce.number().positive(),
}); });
const GetFromGame = z.object({
gameName: z.string().nonempty(),
});
app.get("/api/announcements", async (_, res) => { app.get("/api/announcements", async (_, res) => {
const announcements = await db const announcements = await db
.selectFrom("announcements") .selectFrom("announcements")
@@ -50,6 +54,18 @@ app.get("/api/announcements", async (_, res) => {
res.json(announcements); 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) => { app.get("/api/announcements/:announcementId", async (req, res) => {
const { announcementId } = AnnouncementIdInput.parse(req.params); const { announcementId } = AnnouncementIdInput.parse(req.params);
const announcement = await db const announcement = await db