Skip to content

Commit

Permalink
Merge pull request #15 from ChangePlusPlusVandy/samuel/PWW-41
Browse files Browse the repository at this point in the history
Create getWorkshopsByUserId endpoint
  • Loading branch information
lolitaroz authored Dec 8, 2024
2 parents b2bb393 + 8db189a commit df90a2d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
20 changes: 20 additions & 0 deletions api/src/controllers/workshopController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
36 changes: 35 additions & 1 deletion api/src/routes/workshop.ts
Original file line number Diff line number Diff line change
@@ -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();

Expand Down Expand Up @@ -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;

0 comments on commit df90a2d

Please sign in to comment.