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 all commits
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
23 changes: 23 additions & 0 deletions config/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,26 @@ paths:
description: Event created
default:
description: Internal Server Error

/event:
get:
tags:
- Get Data API
security :
- ApiTokens: []
- ApiKey: []
summary: Returns event details or all events
parameters:
- in: query
name: slug
required: false
schema:
type: string
description : Optional. If provided, fetches a specific event by its slug.
responses:
'200':
description: Success response with event details or all events.
'404':
description: Event Not Found.
default:
description: Internal Server Error.
22 changes: 22 additions & 0 deletions routes/events/Event.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,28 @@ const Event = require("../../schema/events/EventSchema");
const { STATUSCODE, STATUSMESSAGE } = require("../../utils/Status");
const { setTime } = require("../../utils/SetTime");

router.get("/", async (req, res) => {
try {
if (req.query.slug) {
const eventDetails = await Event.findOne({ slug: req.query.slug });

if (eventDetails) {
return res.status(STATUSCODE.OK).json(eventDetails);
}
return res
.status(STATUSCODE.NOT_FOUND)
.json({ message: STATUSMESSAGE.NOT_FOUND });
}

const allEvents = await Event.find({});
res.status(STATUSCODE.OK).json(allEvents);
} catch (error) {
return res
.status(STATUSCODE.INTERNAL_SERVER_ERROR)
.json({ message: STATUSMESSAGE.INTERNAL_SERVER_ERROR });
}
});

router.post("/create", async (req, res) => {
try {
const { slug, ...data } = req.body;
Expand Down
2 changes: 1 addition & 1 deletion utils/Status.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const STATUSMESSAGE = {
UNAUTHORIZED: "Unauthorized !",
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",
PRODUCT_SLUG_ALREADY_EXISTS: "productSlug already exists",
PRODUCT_ADD_FAILED: "Failed to add product",
Expand Down
Loading