minor changes

This commit is contained in:
Bhavnoor Singh Saroya 2025-08-25 14:23:55 -07:00
parent 909b29dfb5
commit af2e220116
30 changed files with 598 additions and 350 deletions

View file

@ -117,6 +117,7 @@ intructorRouter.get("/details/:id", async (req, res) => {
);
console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data);
console.log("Response status:", response.status);
res.status(response.status).json(response.data);
} catch (error) {
console.error("Error fetching assignment details:", error.message);
@ -129,16 +130,20 @@ intructorRouter.get(
"/list/:id",
// passport.authenticate("jwt", { session: false }),
async (req, res) => {
console.log("/list/:id endpoint hit");
// if (req.isAuthenticated()) {
try {
const instructorId = req.params.id;
// console.log("Fetching assignments for instructorId:", instructorId);
console.log("Fetching assignments for instructorId:", instructorId);
const response = await axios.get(
`${DB_ASSIGNMENT_SERVICE_URL}/assignments/instructor/${instructorId}`
);
// console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data);
console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data);
console.log("Response status:", response.status);
res.status(response.status).json(response.data);
} catch (error) {
console.log("Error fetching assignments:", error.response);
console.error("Error fetching assignments:", error.message);
res.status(error.response?.status || 500).json({ error: error.message });
}
// } else {
@ -191,10 +196,10 @@ intructorRouter.delete(
if (!assignmentData) {
return res.status(404).json({ error: "Assignment not found" });
}
}
// Delete the Battlesnake API
if(assignmentData.appname){
if (assignmentData.appname) {
console.log(`Deleting Battlesnake API: ${assignmentData.appname}`);
const deployResponse = await axios.post(`${DEPLOY_API_URL}/${assignmentData.appname}/delete`, {
"appName": assignmentData.appname
@ -206,7 +211,7 @@ 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}`
@ -231,7 +236,7 @@ intructorRouter.get(
`${DB_ASSIGNMENT_SERVICE_URL}/assignments/appname/${appName}`
);
console.log("Response data:", response.data);
res.status(response.status).json({"exists": (response.data !== null && response.data !== undefined)});
res.status(response.status).json({ "exists": (response.data !== null && response.data !== undefined) });
} catch (error) {
console.error("Error fetching assignment by app name:", error.message);
res.status(error.response?.status || 500).json({ error: error.message });
@ -251,7 +256,7 @@ intructorRouter.get(
`${DB_ASSIGNMENT_SERVICE_URL}/assignments/${qrcode}`
);
console.log("Response data:", response.data);
res.status(response.status).json({"exists": (response.data !== null && response.data !== undefined)});
res.status(response.status).json({ "exists": (response.data !== null && response.data !== undefined) });
} catch (error) {
console.error("Error fetching assignment by QR code:", error.message);
res.status(error.response?.status || 500).json({ error: error.message });

View file

@ -7,24 +7,24 @@ const DB_ASSIGNMENT_SERVICE_URL = process.env.DB_ASSIGNMENT_SERVICE_URL;
const DEPLOY_API_URL = process.env.DEPLOY_API_URL || "http://localhost:3600";
studentRouter.post("/save", async (req, res) => {
//get the app name and code and save the latest jupyter file in s3 bucket
const { appName, code } = req.body;
//get the app name and code and save the latest jupyter file in s3 bucket
const { appName, code } = req.body;
console.log("Received save request for app:", appName);
console.log("Received save request for app:", appName);
const notebook = {
cells: [
const notebook = {
cells: [
{
cell_type: "code",
execution_count: null,
metadata: {
language: "python"
language: "python"
},
outputs: [],
source: code.split('\n').map(line => line + '\n')
}
],
metadata: {
],
metadata: {
kernelspec: {
display_name: "Python 3",
language: "python",
@ -34,36 +34,36 @@ studentRouter.post("/save", async (req, res) => {
name: "python",
version: "3.x"
}
},
nbformat: 4,
nbformat_minor: 5
};
},
nbformat: 4,
nbformat_minor: 5
};
// Convert the notebook object to a JSON string and then to base64
const jsonString = JSON.stringify(notebook, null, 2);
const base64 = Buffer.from(jsonString, 'utf-8').toString('base64');
// Convert the notebook object to a JSON string and then to base64
const jsonString = JSON.stringify(notebook, null, 2);
const base64 = Buffer.from(jsonString, 'utf-8').toString('base64');
const notebookName = `${Date.now()}-notebook.ipynb`;
console.log("DEPLOY_API_URL:", DEPLOY_API_URL);
console.log("Uploading notebook:", notebookName, "to app:", appName);
const notebookName = `${Date.now()}-notebook.ipynb`;
console.log("DEPLOY_API_URL:", DEPLOY_API_URL);
console.log("Uploading notebook:", notebookName, "to app:", appName);
await fetch(`${DEPLOY_API_URL}/${appName}/upload`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ notebookName: notebookName, fileContentBase64: base64 })
await fetch(`${DEPLOY_API_URL}/${appName}/upload`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ notebookName: notebookName, fileContentBase64: base64 })
})
.then((response) => {
if (!response.ok) throw new Error("Failed to save notebook");
return response.json();
})
.then((response) => {
if (!response.ok) throw new Error("Failed to save notebook");
return response.json();
})
.then((data) => {
console.log("Notebook saved successfully:", data);
res.status(200).json(data);
})
.catch((error) => {
console.error("Error saving notebook:", error.message);
res.status(500).json({ error: error.message });
});
.then((data) => {
console.log("Notebook saved successfully:", data);
res.status(200).json(data);
})
.catch((error) => {
console.error("Error saving notebook:", error.message);
res.status(500).json({ error: error.message });
});
});
studentRouter.get("/assignment/:qrnum", (req, res) => {
@ -105,7 +105,7 @@ studentRouter.post("/verify", async (req, res) => {
const isPasswordValid = await bcrypt.compare(
password,
response.data.passwordhash
response.data.passwordhash
);
console.log("Password validation result:", isPasswordValid);