From fd993102a0a9f46f9785d1988d78f9276d17524a Mon Sep 17 00:00:00 2001 From: JBB0807 <104856796+JBB0807@users.noreply.github.com> Date: Tue, 6 May 2025 13:28:01 -0700 Subject: [PATCH] fixed editor bug --- assignment-db-service/app.js | 28 +++++++++++++++++-- assignment-service/routes/InstructorRouter.js | 26 +++++++++++++++++ assignment-service/routes/StudentRouter.js | 4 +-- auth-service/.env | 2 +- 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/assignment-db-service/app.js b/assignment-db-service/app.js index 61a7a37..91d19be 100644 --- a/assignment-db-service/app.js +++ b/assignment-db-service/app.js @@ -122,8 +122,31 @@ app.get("/assignments/instructor/:instructorId", async (req, res) => { } }); -// Read Assignment -app.get("/assignments/:qrNumber", async (req, res) => { +//Get assignment by assignmentid +app.get("/assignments/:id", async (req, res) => { + try { + const { id } = req.params; + console.log("Fetching assignment with ID:", id); + + const assignment = await prisma.assignments.findUnique({ + where: { assignmentid: parseInt(id) }, + }); + + if (!assignment) { + console.log("No assignment found for ID:", id); + return res.status(404).json({ message: "Assignment not found" }); + } + + console.log("Assignment found:", assignment); + res.json(assignment); + } catch (err) { + console.error("Error fetching assignment:", err.message); + res.status(500).json({ error: err.message }); + } +}); + +// Get Assignment by QR Code Number +app.get("/assignments/qr/:qrNumber", async (req, res) => { try { console.log("Fetching assignment with QR Code Number:", req.params.qrNumber); @@ -222,3 +245,4 @@ app.delete("/assignments/:id", async (req, res) => { app.listen(port, () => { console.log(`Server running at http://localhost:${port}`); }); + diff --git a/assignment-service/routes/InstructorRouter.js b/assignment-service/routes/InstructorRouter.js index 55af452..22777ca 100644 --- a/assignment-service/routes/InstructorRouter.js +++ b/assignment-service/routes/InstructorRouter.js @@ -132,7 +132,33 @@ intructorRouter.delete( // passport.authenticate("jwt", { session: false }), async (req, res) => { try { + const assignmentId = req.params.id; + + //get the assignment data from the database + console.log("Fetching assignment data for ID:", assignmentId); + const assignmentResponse = await axios.get( + `${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}` + ); + const assignmentData = assignmentResponse.data; + console.log("Assignment data:", assignmentData); + + if (!assignmentData) { + return res.status(404).json({ error: "Assignment not found" }); + } + + // Delete the Battlesnake API + console.log('Deploying a new Battlesnake API'); + console.log("DEPLOY_API_URL:", DEPLOY_API_URL, assignmentData.appname); + const deployResponse = await axios.post(`${DEPLOY_API_URL}/${assignmentData.appname}/delete`, { + "appName": assignmentData.appname + }); + //throw error if the response is not 200 + if (deployResponse.status !== 200) { + throw new Error(`Failed to delete Battlesnake API: ${deployResponse.statusText}`); + } + console.log('Response from DEPLOY_API_URL:', deployResponse.data); + const response = await axios.delete( `${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}` ); diff --git a/assignment-service/routes/StudentRouter.js b/assignment-service/routes/StudentRouter.js index 80f9f79..947820c 100644 --- a/assignment-service/routes/StudentRouter.js +++ b/assignment-service/routes/StudentRouter.js @@ -14,7 +14,7 @@ studentRouter.get("/assignment/:qrnum", (req, res) => { const qrnum = req.params.qrnum; console.log("Fetching details for qr number:", qrnum); axios - .get(`${DB_ASSIGNMENT_SERVICE_URL}/assignments/${qrnum}`) + .get(`${DB_ASSIGNMENT_SERVICE_URL}/assignments/qr/${qrnum}`) .then((response) => { console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data); res.status(response.status).json(response.data); @@ -40,7 +40,7 @@ studentRouter.post("/verify", async (req, res) => { console.log(`Fetching from URL: ${DB_ASSIGNMENT_SERVICE_URL}/assignments/${qrNumber}`); const response = await axios.get( - `${DB_ASSIGNMENT_SERVICE_URL}/assignments/${qrNumber}` + `${DB_ASSIGNMENT_SERVICE_URL}/assignments/qr/${qrNumber}` ); console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data); diff --git a/auth-service/.env b/auth-service/.env index a5e74f3..75d4e76 100644 --- a/auth-service/.env +++ b/auth-service/.env @@ -2,7 +2,7 @@ GOOGLE_CLIENT_ID = "485880105639-1in8tvb6ondnn198rasuj2d8ank06ntp.apps.googleuse GOOGLE_CLIENT_SECRET = "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" GOOGLE_CALLBACK_URL = "https://byte-camp-auth-service.fly.dev/auth/google/callback" LOGIN_REDIRECT_URL = "https://bytecamp-web.fly.dev/" -ACCEPTED_ORIGINS ="https://bytecamp-web.fly.dev,https://byte-camp-auth-service.fly.dev" +ACCEPTED_ORIGINS ="https://bytecamp-web.fly.dev,https://byte-camp-auth-service.fly.dev,http://localhost:5173" #DB_USER_SERVICE_URL = "http://localhost:3000/" DB_USER_SERVICE_URL = "http://db-user-service.internal:3000/" AUTH_SESSION_KEY = "f3f4d8e6b17a4b3abdc8e9a2c0457aaf91c0d5f6e3b7a9c8df624bd71ea35f42"