diff --git a/api/src/controllers/workshopController.ts b/api/src/controllers/workshopController.ts index 8fd36c4..106955f 100644 --- a/api/src/controllers/workshopController.ts +++ b/api/src/controllers/workshopController.ts @@ -36,6 +36,26 @@ export const getWorkshop = async (req: Request, res: Response) => { } }; +export const getWorkshopsByUserId = async (req: Request, res: Response) => { + try { + const { userId } = req.params; + + const workshops = await Workshop.find({ + $or: [{ mentor: userId }, { mentee: userId }], + }); + + if (workshops.length === 0) { + return res + .status(404) + .json({ message: "No workshops found for this user" }); + } + + res.status(200).json(workshops); + } catch (error) { + res.status(500).json({ message: "Error retrieving workshops", error }); + } +}; + // POPULATE VERSION (if details of mentor/mentee objects are needed on the frontend like name or picture) // import { Request, Response } from 'express'; diff --git a/api/src/routes/workshop.ts b/api/src/routes/workshop.ts index b392062..32094f1 100644 --- a/api/src/routes/workshop.ts +++ b/api/src/routes/workshop.ts @@ -1,7 +1,12 @@ import express from "express"; import mongoose from "mongoose"; import dbConnect from "../config/db"; // Import the dbConnect function -// import { validateAccessToken } from "../controllers/auth0-middleware"; + +import { + createWorkshop, + getWorkshop, + getWorkshopsByUserId, +} from "../controllers/workshopController"; const router = express.Router(); @@ -44,4 +49,33 @@ router.post("/create-workshop", async (req: any, res: any) => { } }); +// router.post("/workshops", createWorkshop) +// router.get('/workshops/:id', getWorkshop); +router.get( + "/workshops/:id", + async (req: express.Request, res: express.Response) => { + await getWorkshop(req, res); + }, +); + +// Route to get workshops by user ID +router.get( + "/workshops/user/:userId", + async (req: express.Request, res: express.Response) => { + await getWorkshopsByUserId(req, res); + }, +); + +// POPULATE VERSION (if details of mentor/mentee objects are needed on the frontend like name or picture) + +// import express from 'express'; +// import { createWorkshop, getWorkshop } from '../controllers/workshopController'; + +// const router = express.Router(); + +// router.post('/workshops', createWorkshop); +// router.get('/workshops/:id', getWorkshop); + +// export default router; + export default router;