Skip to content

Commit

Permalink
add submission status endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayush272002 committed Dec 7, 2024
1 parent 54fbb34 commit 034467b
Show file tree
Hide file tree
Showing 3 changed files with 9,050 additions and 33,911 deletions.
43 changes: 42 additions & 1 deletion apps/backend/src/controllers/assignmentController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ const submitAssignment = async (req: Request, res: Response) => {

const redisManager = RedisManager.getInstance();
let sentResponse = false;
redisManager.subscribe(SUBMIT, (message) => {
redisManager.subscribe(SUBMIT, (message: any) => {
if (sentResponse) return;

console.log(message);
Expand Down Expand Up @@ -355,10 +355,51 @@ const createAssignment = async (req: Request, res: Response) => {
}
};

const getSubmissionStatus = async (req: Request, res: Response) => {
console.log('control here');
const assignmentId = req.params.id;
const userId = req.body.userId;

try {
const submission = await prisma.submission.findFirst({
where: {
assignmentId,
studentId: userId,
},
select: {
submittedAt: true,
marksAchieved: true,
logs: true,
},
});

if (!submission) {
return res.status(200).json({ status: 'unsubmitted' });
}

if (submission.marksAchieved === -1) {
return res
.status(200)
.json({ status: 'submitted', logs: submission.logs });
}

console.log(submission);
return res.status(200).json({
status: 'marked',
marksAchieved: submission.marksAchieved,
logs: submission.logs,
});
} catch (error) {
console.error('Error fetching submission status:', error);
return res.status(500).json({ message: 'Internal server error.' });
}
};

export {
allAssignments,
getAssignment,
updateAssignment,
createAssignment,
submitAssignment,
getSubmissionStatus,
};
3 changes: 3 additions & 0 deletions apps/backend/src/routes/assignment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
allAssignments,
createAssignment,
getAssignment,
getSubmissionStatus,
submitAssignment,
updateAssignment,
} from '../controllers/assignmentController';
Expand All @@ -21,4 +22,6 @@ router

router.post('/:id/submit', authMiddleware, submitAssignment);

router.get('/:id/status', authMiddleware, getSubmissionStatus);

export const assignmentRouter = router;
Loading

0 comments on commit 034467b

Please sign in to comment.