diff --git a/backend/app.js b/backend/app.js index 69d7b2f..f998742 100644 --- a/backend/app.js +++ b/backend/app.js @@ -12,6 +12,8 @@ import { db } from "./database/datatase.js"; import { eventRouter } from "./routes/eventRoutes.js"; import { filterRoutes } from "./routes/filterRoutes.js"; import { joinGroupRouter } from "./routes/groupLobbyRouter.js"; +import { groupParticipantsRouter } from "./routes/groupParticipantsRoutes.js"; + //.env files const SERVER_PORT = process.env.PORT; @@ -34,6 +36,7 @@ app.use("/participants", participantRouter); app.use("/events", eventRouter); app.use("/filter", filterRoutes); app.use("/joingroup", joinGroupRouter); +app.use("/getgroup", groupParticipantsRouter); //server Start app.listen(SERVER_PORT, () => { diff --git a/backend/controllers/getGroupParticipants.js b/backend/controllers/getGroupParticipants.js new file mode 100644 index 0000000..1697b40 --- /dev/null +++ b/backend/controllers/getGroupParticipants.js @@ -0,0 +1,45 @@ +import { lobbyModel } from "../models/lobbyEventModel.js"; + +const getgroupParticipants = async (req, res) => { + const lobbyId = req.query.lobby_id; // Assume lobbyId is passed as a query parameter + + if (!lobbyId) { + return res.status(400).json({ + status: "error", + message: "Lobby ID is required", + }); + } + + try { + // Find the lobby by ID + const lobby = await lobbyModel.findById(lobbyId).populate('participants'); // Populate participants (if needed) + + if (!lobby) { + return res.status(404).json({ + status: "error", + message: "Lobby not found", + }); + } + + // Return the participants of the group + return res.status(200).json({ + status: "success", + message: "Group participants fetched successfully", + data: { + lobbyId: lobby._id, + name: lobby.name, + description: lobby.description, + participants: lobby.participants, // You can expand this if you want user details like name, email, etc. + eventId: lobby.eventId, + }, + }); + } catch (error) { + console.error("Error fetching group participants:", error); + res.status(500).json({ + status: "error", + message: "Internal Server Error", + }); + } +}; + +export { getgroupParticipants }; diff --git a/backend/controllers/joinGroupController.js b/backend/controllers/joinGroupController.js index 6c5e717..04902d3 100644 --- a/backend/controllers/joinGroupController.js +++ b/backend/controllers/joinGroupController.js @@ -1,14 +1,20 @@ import { eventModel } from "../models/eventModel.js"; import { lobbyModel } from "../models/lobbyEventModel.js"; -import { participants } from "./participantController.js"; import { userModel } from "../models/userModel.js"; + const joinGroupController = async (req, res) => { - const userId = req.participant.userId; - const eventId = req.participant.eventId; + const { userId, eventId } = req.participant || {}; // Ensure participant info is provided + + if (!userId || !eventId) { + return res.status(400).json({ + status: "error", + message: "Missing userId or eventId in the request", + }); + } try { + // Find the user const user = await userModel.findById(userId); - if (!user) { return res.status(404).json({ status: "error", @@ -24,9 +30,16 @@ const joinGroupController = async (req, res) => { }); } - const event = await eventModel.findById({ _id: eventId }); - const eventobj = event[0]; + // Find the event by ID + const event = await eventModel.findById(eventId); + if (!event) { + return res.status(404).json({ + status: "error", + message: "Event not found", + }); + } + // Find or create a lobby for the event let lobby = await lobbyModel.findOne({ eventId }); if (!lobby) { @@ -38,10 +51,14 @@ const joinGroupController = async (req, res) => { eventId: eventId, }); + // Save the lobby and update the user's lobbyStatus await lobby.save(); - user.lobbyStatus = true; await user.save(); + + // Add lobby_id to the request object + req.lobby_id = lobby._id; + // Respond with success message and lobby details return res.status(200).json({ status: "success", @@ -55,8 +72,10 @@ const joinGroupController = async (req, res) => { }, }); } else { - // If the lobby exists, add the user to the participants array (if not already present) + // If the lobby exists, check if the user is already in the participants list if (lobby.participants.includes(userId)) { + req.lobby_id = lobby._id; // Add lobby_id to the request object + return res.status(200).json({ status: "success", message: "User is already present in the event/lobby", @@ -69,10 +88,12 @@ const joinGroupController = async (req, res) => { }, }); } else { + // If the user is not in the lobby, add the user to the participants array lobby.participants.push(userId); await lobby.save(); - // Respond with success message and updated lobby details + req.lobby_id = lobby._id; // Add lobby_id to the request object + return res.status(200).json({ status: "success", message: "Joined the group successfully", diff --git a/backend/controllers/participantController.js b/backend/controllers/participantController.js index 9f14017..228e3d8 100644 --- a/backend/controllers/participantController.js +++ b/backend/controllers/participantController.js @@ -30,8 +30,6 @@ const participants = async (req, res) => { const eventId = req.body.eventId; const userId = req.user.userId; - - const newParticipant = await participantModel.create({ eventId: eventId, userId: userId, diff --git a/backend/middlewares/joinGroupAuthentication.js b/backend/middlewares/joinGroupAuthentication.js index 8e7b709..fda84fd 100644 --- a/backend/middlewares/joinGroupAuthentication.js +++ b/backend/middlewares/joinGroupAuthentication.js @@ -2,13 +2,9 @@ import { participantModel } from "../models/participantsModel.js"; const joinGroupAuthentication = async (req, res, next) => { const userId = req.user.userId; - const groupId = req.params.groupId; - const enterOtp = req.body.otp; - console.log(userId, groupId, enterOtp); - if (!userId || !groupId) { return res.json({ message: "Missing UserID and groupId", @@ -47,3 +43,5 @@ const joinGroupAuthentication = async (req, res, next) => { }; export { joinGroupAuthentication }; + + diff --git a/backend/routes/groupLobbyRouter.js b/backend/routes/groupLobbyRouter.js index 1645220..3b7c814 100644 --- a/backend/routes/groupLobbyRouter.js +++ b/backend/routes/groupLobbyRouter.js @@ -6,6 +6,6 @@ import { joinGroupController } from "../controllers/joinGroupController.js"; const joinGroupRouter = Router(); joinGroupRouter.use(authentication); -joinGroupRouter.use("/:groupId", joinGroupAuthentication, joinGroupController); +joinGroupRouter.post("/:groupId", joinGroupAuthentication, joinGroupController); export { joinGroupRouter }; diff --git a/backend/routes/groupParticipantsRoutes.js b/backend/routes/groupParticipantsRoutes.js new file mode 100644 index 0000000..35dcda6 --- /dev/null +++ b/backend/routes/groupParticipantsRoutes.js @@ -0,0 +1,10 @@ +import express from "express"; +// import { joinGroupAuthentication } from "../middlewares/joinGroupAuthentication.js"; // Uncomment if using middleware +import { getgroupParticipants } from "../controllers/getGroupParticipants.js"; + +const groupParticipantsRouter = express.Router(); + +// This route will use the controller to return group participants +groupParticipantsRouter.get("/:lobbyId", getgroupParticipants); + +export { groupParticipantsRouter }; diff --git a/backend/routes/participants.js b/backend/routes/participants.js index d2820c2..d738356 100644 --- a/backend/routes/participants.js +++ b/backend/routes/participants.js @@ -7,3 +7,6 @@ participantRouter.use(authentication); participantRouter.post("/", participants); export { participantRouter }; + + + diff --git a/frontend/src/pages/CategoriesPage.jsx b/frontend/src/pages/CategoriesPage.jsx index 95707bf..41d603c 100644 --- a/frontend/src/pages/CategoriesPage.jsx +++ b/frontend/src/pages/CategoriesPage.jsx @@ -1,6 +1,14 @@ import React, { useState, useEffect } from "react"; -const categories = ["music", "nightlife", "gaming", "technology", "charity", "arts", "environments"]; +const categories = [ + "music", + "nightlife", + "gaming", + "technology", + "charity", + "arts", + "environments", +]; const CategoriesPage = () => { const [data, setData] = useState({}); @@ -48,7 +56,9 @@ const CategoriesPage = () => {
{categories.map((category) => (
-

{category}

+

+ {category} +

{data[category]?.length > 0 ? ( data[category].map((event) => ( @@ -88,25 +98,3 @@ const CategoriesPage = () => { }; export default CategoriesPage; - - - - - - - - - - - - - - -const gridproblem(i,j,currentSum){ - if(i == M-1 && j == N-1 ){ - return currentSum - } - -} - -