From f60dc3b01829a883fcca5d3ed3acc54b8126197f Mon Sep 17 00:00:00 2001 From: Maxime Cannoodt Date: Tue, 30 Aug 2022 13:52:52 +0200 Subject: [PATCH] embed controller --- .../note/embeds/embeds.get.controller.ts | 24 +++++++++++++++++++ .../controllers/note/embeds/embeds.router.ts | 6 +++++ .../controllers/note/note.get.controller.ts | 1 + server/src/controllers/note/note.router.ts | 2 ++ 4 files changed, 33 insertions(+) create mode 100644 server/src/controllers/note/embeds/embeds.get.controller.ts create mode 100644 server/src/controllers/note/embeds/embeds.router.ts diff --git a/server/src/controllers/note/embeds/embeds.get.controller.ts b/server/src/controllers/note/embeds/embeds.get.controller.ts new file mode 100644 index 0000000..cc78925 --- /dev/null +++ b/server/src/controllers/note/embeds/embeds.get.controller.ts @@ -0,0 +1,24 @@ +import express, { + type NextFunction, + type Request, + type Response, +} from "express"; +import { getEmbed } from "../../../db/embed.dao"; + +export async function getNoteController( + req: Request, + res: Response, + next: NextFunction +): Promise { + const { id: note_id, embed_id } = req.params; + try { + const embed = await getEmbed(note_id, embed_id); + if (embed != null) { + res.status(200).json(embed).send(); + } else { + res.status(404).send(); + } + } catch (err) { + next(err); + } +} diff --git a/server/src/controllers/note/embeds/embeds.router.ts b/server/src/controllers/note/embeds/embeds.router.ts new file mode 100644 index 0000000..5fd5704 --- /dev/null +++ b/server/src/controllers/note/embeds/embeds.router.ts @@ -0,0 +1,6 @@ +import express from "express"; +import { getNoteController } from "../note.get.controller"; + +export const embedsRoute = express.Router({ mergeParams: true }); + +embedsRoute.get("/:embed_id", getNoteController); diff --git a/server/src/controllers/note/note.get.controller.ts b/server/src/controllers/note/note.get.controller.ts index 11a473d..7cbe8f9 100644 --- a/server/src/controllers/note/note.get.controller.ts +++ b/server/src/controllers/note/note.get.controller.ts @@ -3,6 +3,7 @@ import { getExpiredNoteFilter } from "../../lib/expiredNoteFilter"; import EventLogger from "../../logging/EventLogger"; import { getConnectingIp } from "../../util"; import { getNote } from "../../db/note.dao"; + export async function getNoteController( req: Request, res: Response, diff --git a/server/src/controllers/note/note.router.ts b/server/src/controllers/note/note.router.ts index dba4e49..cd62c1c 100644 --- a/server/src/controllers/note/note.router.ts +++ b/server/src/controllers/note/note.router.ts @@ -1,6 +1,7 @@ import bodyParser from "body-parser"; import express from "express"; import rateLimit from "express-rate-limit"; +import { embedsRoute } from "./embeds/embeds.router"; import { getNoteController } from "./note.get.controller"; import { postNoteController } from "./note.post.controller"; @@ -28,3 +29,4 @@ notesRoute.use(uploadLimit); notesRoute.use(jsonParser); notesRoute.post("", postRateLimit, postNoteController); notesRoute.get("/:id", getRateLimit, getNoteController); +notesRoute.use("/:id/embeds/", embedsRoute);