generated from agiledev-students-fall2023/generic-project-repository
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #188 from agiledev-students-fall2023/sprint/2/task…
…/145 Added API endpoint for student issue overlay
- Loading branch information
Showing
4 changed files
with
122 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
back-end/src/controllers/studentIssueViewDetailsHandler.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
// const StudentIssue = require('../models/studentIssue'); | ||
|
||
// async function getStudentIssueDetails(req, res) { | ||
// try { | ||
// const { id } = req.params; | ||
// const studentIssue = await StudentIssue.findById(id); | ||
// if (!studentIssue) { | ||
// return res.status(404).json({ message: 'Student issue not found' }); | ||
// } | ||
// return res.status(200).json(studentIssue); | ||
// } catch (error) { | ||
// console.error(error); | ||
// return res.status(500).json({ message: 'Server error' }); | ||
// } | ||
// } | ||
|
||
// module.exports = { getStudentIssueDetails }; | ||
|
||
import axios from "axios"; | ||
|
||
// The function retrieves all the issues related to this student | ||
export async function studentIssueViewDetailsHandler(req, res) { | ||
const { paramName } = req.params; | ||
const { studentNetID } = req.params; | ||
try { | ||
// Assuming the data you want is at the response.data property | ||
const response = await axios.get( | ||
`${process.env.BACKEND_URL}/api/issues/student/${studentNetID}` | ||
); | ||
|
||
// Assuming response.data is an array of items and each item has a index | ||
const filteredData = response.data.filter( | ||
(item) => String(item.index) === String(paramName) | ||
); | ||
|
||
res.json(filteredData); // Send only the data that matches the specific issue index | ||
} catch (error) { | ||
// Log the error and send an appropriate response | ||
console.error("Error retrieving data:", error.message); | ||
res.status(500).send("An error occurred while retrieving the data."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import express from "express"; | ||
import { studentIssueViewDetailsHandler } from "../controllers/studentIssueViewDetailsHandler.js"; | ||
|
||
const router = express.Router(); | ||
|
||
router.get("/:studentNetID/:paramName", studentIssueViewDetailsHandler); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters