Skip to content

Commit

Permalink
feature/implementingGetEventByIdRoute
Browse files Browse the repository at this point in the history
  • Loading branch information
ezequielramos committed Feb 28, 2024
1 parent 4dccacc commit d3ec9fa
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/controllers/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,8 @@ function createEvent({ created_date, camera }: { created_date?: string; camera:
return eventFace;
}

export { createEvent };
function getEvent(eventId: number) {
return events[eventId];
}

export { createEvent, getEvent };
28 changes: 27 additions & 1 deletion src/routes/events.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Express, Request, Response } from 'express';
import multer from 'multer';
import { validAuthorization } from '../services/route_middlewares';
import { createEvent } from '../controllers/events';
import { createEvent, getEvent } from '../controllers/events';

const upload = multer({
storage: multer.memoryStorage()
Expand Down Expand Up @@ -84,6 +84,32 @@ function loadEventsRoutes(app: Express) {
});
});

app.get('/events/faces/:id/', validAuthorization, async (req: Request, res: Response) => {
const eventId = Number(req.params.id);
if (Number.isNaN(eventId)) {
return res.status(400).json({
code: "BAD_PARAM",
desc: "ID must be a positive integer."
});
}
if (eventId < 1) {
return res.status(400).json({
code: "BAD_PARAM",
desc: "ID must be non-zero uint64 number."
});
}

const event = getEvent(eventId);
if (!event) {
return res.status(404).json({
code: "NOT_FOUND",
desc: "No FaceEvent matches the given query."
});
}

return res.status(200).json(event);
});

app.get('/events/faces/', validAuthorization, async (req: Request, res: Response) => {
return res.status(200).json({
"next_page": null,
Expand Down

0 comments on commit d3ec9fa

Please sign in to comment.