Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added get routes for events #46

Merged
merged 5 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions config/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,25 @@ paths:
description: Event created
default:
description: Internal Server Error

/event/{eventSlug}:
get:
tags:
- Get Data API
security :
- ApiTokens: []
- ApiKey: []
summary: GET Event by slug
parameter:
- in: path
name: eventSlug
required: true
schema:
type: string
responses:
'200':
description: OK.
'404':
description: Event Not Found.
default:
description: Internal Server Error.
15 changes: 14 additions & 1 deletion routes/display/Display.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

const express = require("express");
const User = require("../../schema/user/UserSchema");
const { STATUSCODE } = require("../../utils/Status");
const { STATUSCODE, STATUSMESSAGE } = require("../../utils/Status");
const Event = require("../../schema/events/EventSchema");
const router = express.Router();

// Route 1 - Show all avaialble Users in the DB
Expand All @@ -25,4 +26,16 @@ router.get("/clubs", async (req, res) => {
}
});

// * Route 3 - Show all available Events in the DB
router.get("/events", async (req, res) => {
try {
const allEvents = await Event.find();
res.status(STATUSCODE.OK).json(allEvents);
} catch (err) {
res
.status(STATUSCODE.INTERNAL_SERVER_ERROR)
.json(STATUSMESSAGE.INTERNAL_SERVER_ERROR);
}
});

tamalCodes marked this conversation as resolved.
Show resolved Hide resolved
module.exports = router;
18 changes: 18 additions & 0 deletions routes/events/Event.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@ const Event = require("../../schema/events/EventSchema");
const { STATUSCODE, STATUSMESSAGE } = require("../../utils/Status");
const { setTime } = require("../../utils/SetTime");

router.get("/:eventSlug", async (req, res) => {
try {
const { eventSlug } = req.params;
const event = await Event.findOne({ slug: eventSlug });
if (!event) {
return res
.status(STATUSCODE.NOT_FOUND)
.json(STATUSMESSAGE.EVENT_NOT_FOUND);
}

res.status(STATUSCODE.OK).json(event);
} catch (err) {
res
.status(STATUSCODE.INTERNAL_SERVER_ERROR)
.json(STATUSMESSAGE.INTERNAL_SERVER_ERROR);
}
tamalCodes marked this conversation as resolved.
Show resolved Hide resolved
});

tamalCodes marked this conversation as resolved.
Show resolved Hide resolved
router.post("/create", async (req, res) => {
try {
const { slug, ...data } = req.body;
Expand Down
1 change: 1 addition & 0 deletions utils/Status.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const STATUSMESSAGE = {
FORBIDDEN: "Forbidden !",
NOT_FOUND: "Not found !",
EVENT_SLUG_ALREADY_EXISTS: "Event slug already exists",
EVENT_NOT_FOUND: "Event not found !",
tamalCodes marked this conversation as resolved.
Show resolved Hide resolved
CREATE_EVENT_FAILED: "Failed to create event",
};

Expand Down
Loading