diff --git a/assignment-db-service/app.js b/assignment-db-service/app.js index bfb2fbd..8216bf2 100644 --- a/assignment-db-service/app.js +++ b/assignment-db-service/app.js @@ -236,11 +236,13 @@ app.put("/assignments/:id", async (req, res) => { app.delete("/assignments/:id", async (req, res) => { try { const { id } = req.params; + console.log("Deleting assignment with ID:", id); await prisma.assignments.delete({ where: { assignmentid: parseInt(id) }, }); + console.log("Assignment deleted successfully:", id); res.json({ message: "Assignment deleted successfully" }); } catch (err) { console.error("Error deleting assignment:", err.message); diff --git a/assignment-service/routes/InstructorRouter.js b/assignment-service/routes/InstructorRouter.js index 8d6fcc1..c2187b0 100644 --- a/assignment-service/routes/InstructorRouter.js +++ b/assignment-service/routes/InstructorRouter.js @@ -66,7 +66,7 @@ intructorRouter.post( const updatedAssignmentData = { assignmenturl: `${PROXY_URL}/${ipv6}`, } - + console.log("Updating assignment with deployment details:", updatedAssignmentData); const updateRespone = await axios.put( `${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}`, @@ -196,7 +196,6 @@ intructorRouter.delete( // Delete the Battlesnake API if(assignmentData.appname){ console.log(`Deleting Battlesnake API: ${assignmentData.appname}`); - console.log("DEPLOY_API_URL:", DEPLOY_API_URL, assignmentData.appname); const deployResponse = await axios.post(`${DEPLOY_API_URL}/${assignmentData.appname}/delete`, { "appName": assignmentData.appname }); @@ -208,9 +207,11 @@ intructorRouter.delete( console.log('Response from DEPLOY_API_URL:', deployResponse.data); } + console.log("Deleting assignment from database:", assignmentId); const response = await axios.delete( `${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}` ); + console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data); res.status(response.status).json(response.data); } catch (error) { res.status(error.response?.status || 500).json({ error: error.message }); diff --git a/deployment-service/src/index.js b/deployment-service/src/index.js index 64ad909..2e60234 100644 --- a/deployment-service/src/index.js +++ b/deployment-service/src/index.js @@ -230,17 +230,21 @@ app.post("/:appName/delete", async (req, res) => { //check if the app exists console.log("Checking if app exists:", appName); + const appCheck = await fly.get(`/apps/${appName}`); console.log("App check response:", appCheck.status); - if (appCheck.status !== 200) { - console.log("App not found:", appName); - return res.json({ status: "App not found", app: appName }); - } - + await fly.delete(`/apps/${appName}`); return res.json({ status: "deleted", app: appName }); } catch (err) { + + //handle the 404 error and not treat it as a failure (no app to delete) + if (err.response?.status === 404) { + console.log("App not found, nothing to delete:", appName); + return res.status(200).json({ error: "App not found" }); + } + const errorData = err.response?.data || err.stack || err.message; console.error("App deletion error:", errorData); return res.status(500).json({ errorData });