Skip to content

Commit

Permalink
feat: added get routes for events (#46)
Browse files Browse the repository at this point in the history
* feat: get routes for events

* fix: single route for event details

* fix: updated api docs

* fix: code updated for better readability

---------

Co-authored-by: Tamal Das <tamalcodes@gmail.com>
  • Loading branch information
Sundroid-ops and tamalCodes committed Feb 3, 2024
1 parent 9f1f1fb commit bec5bc7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
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 !",
CREATE_EVENT_FAILED: "Failed to create event",
PRODUCT_SLUG_ALREADY_EXISTS: "productSlug already exists",
PRODUCT_ADD_FAILED: "Failed to add product",
Expand Down

0 comments on commit bec5bc7

Please sign in to comment.