fixed editor bug

This commit is contained in:
JBB0807 2025-05-06 13:28:01 -07:00
parent ee04a7e8ef
commit fd993102a0
4 changed files with 55 additions and 5 deletions

View file

@ -122,8 +122,31 @@ app.get("/assignments/instructor/:instructorId", async (req, res) => {
} }
}); });
// Read Assignment //Get assignment by assignmentid
app.get("/assignments/:qrNumber", async (req, res) => { 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 { try {
console.log("Fetching assignment with QR Code Number:", req.params.qrNumber); 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, () => { app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`); console.log(`Server running at http://localhost:${port}`);
}); });

View file

@ -132,7 +132,33 @@ intructorRouter.delete(
// passport.authenticate("jwt", { session: false }), // passport.authenticate("jwt", { session: false }),
async (req, res) => { async (req, res) => {
try { try {
const assignmentId = req.params.id; 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( const response = await axios.delete(
`${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}` `${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}`
); );

View file

@ -14,7 +14,7 @@ studentRouter.get("/assignment/:qrnum", (req, res) => {
const qrnum = req.params.qrnum; const qrnum = req.params.qrnum;
console.log("Fetching details for qr number:", qrnum); console.log("Fetching details for qr number:", qrnum);
axios axios
.get(`${DB_ASSIGNMENT_SERVICE_URL}/assignments/${qrnum}`) .get(`${DB_ASSIGNMENT_SERVICE_URL}/assignments/qr/${qrnum}`)
.then((response) => { .then((response) => {
console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data); console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data);
res.status(response.status).json(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}`); console.log(`Fetching from URL: ${DB_ASSIGNMENT_SERVICE_URL}/assignments/${qrNumber}`);
const response = await axios.get( 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); console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data);

View file

@ -2,7 +2,7 @@ GOOGLE_CLIENT_ID = "485880105639-1in8tvb6ondnn198rasuj2d8ank06ntp.apps.googleuse
GOOGLE_CLIENT_SECRET = "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" GOOGLE_CLIENT_SECRET = "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"
GOOGLE_CALLBACK_URL = "https://byte-camp-auth-service.fly.dev/auth/google/callback" GOOGLE_CALLBACK_URL = "https://byte-camp-auth-service.fly.dev/auth/google/callback"
LOGIN_REDIRECT_URL = "https://bytecamp-web.fly.dev/" 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://localhost:3000/"
DB_USER_SERVICE_URL = "http://db-user-service.internal:3000/" DB_USER_SERVICE_URL = "http://db-user-service.internal:3000/"
AUTH_SESSION_KEY = "f3f4d8e6b17a4b3abdc8e9a2c0457aaf91c0d5f6e3b7a9c8df624bd71ea35f42" AUTH_SESSION_KEY = "f3f4d8e6b17a4b3abdc8e9a2c0457aaf91c0d5f6e3b7a9c8df624bd71ea35f42"