Skip to content
Open
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
3 changes: 3 additions & 0 deletions backend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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, () => {
Expand Down
45 changes: 45 additions & 0 deletions backend/controllers/getGroupParticipants.js
Original file line number Diff line number Diff line change
@@ -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 };
39 changes: 30 additions & 9 deletions backend/controllers/joinGroupController.js
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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) {
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 0 additions & 2 deletions backend/controllers/participantController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions backend/middlewares/joinGroupAuthentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -47,3 +43,5 @@ const joinGroupAuthentication = async (req, res, next) => {
};

export { joinGroupAuthentication };


2 changes: 1 addition & 1 deletion backend/routes/groupLobbyRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
10 changes: 10 additions & 0 deletions backend/routes/groupParticipantsRoutes.js
Original file line number Diff line number Diff line change
@@ -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 };
3 changes: 3 additions & 0 deletions backend/routes/participants.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ participantRouter.use(authentication);
participantRouter.post("/", participants);

export { participantRouter };



36 changes: 12 additions & 24 deletions frontend/src/pages/CategoriesPage.jsx
Original file line number Diff line number Diff line change
@@ -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({});
Expand Down Expand Up @@ -48,7 +56,9 @@ const CategoriesPage = () => {
<main className="container mx-auto px-4 py-8">
{categories.map((category) => (
<section key={category} className="mb-12">
<h2 className="text-3xl font-semibold mb-4 capitalize">{category}</h2>
<h2 className="text-3xl font-semibold mb-4 capitalize">
{category}
</h2>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
{data[category]?.length > 0 ? (
data[category].map((event) => (
Expand Down Expand Up @@ -88,25 +98,3 @@ const CategoriesPage = () => {
};

export default CategoriesPage;














const gridproblem(i,j,currentSum){
if(i == M-1 && j == N-1 ){
return currentSum
}

}