feat: verbinding tussen service laag en api endpoint van submissions van een assignment

This commit is contained in:
Adriaan Jacquet 2025-03-12 15:26:50 +01:00
parent fd693dc55f
commit 788ca54742
2 changed files with 22 additions and 6 deletions

View file

@ -1,5 +1,5 @@
import { Request, Response } from 'express';
import { getAllAssignments, getAssignment } from '../services/assignments.js';
import { getAllAssignments, getAssignment, getAssignmentsSubmissions } from '../services/assignments.js';
// Typescript is annoy with with parameter forwarding from class.ts
interface AssignmentParams {
@ -42,3 +42,22 @@ export async function getAssignmentHandler(
res.json(assignment);
}
export async function getAssignmentsSubmissionsHandler(
req: Request<AssignmentParams>,
res: Response,
): Promise<void> {
const classid = req.params.classid;
const assignmentNumber = +req.params.id;
if (isNaN(assignmentNumber)) {
res.status(400).json({ error: 'Assignment id must be a number' });
return;
}
const submissions = await getAssignmentsSubmissions(classid, assignmentNumber);
res.json({
submissions: submissions,
});
}

View file

@ -2,6 +2,7 @@ import express from 'express';
import {
getAllAssignmentsHandler,
getAssignmentHandler,
getAssignmentsSubmissionsHandler,
} from '../controllers/assignments.js';
import groupRouter from './groups.js';
@ -13,11 +14,7 @@ router.get('/', getAllAssignmentsHandler);
// Information about an assignment with id 'id'
router.get('/:id', getAssignmentHandler);
router.get('/:id/submissions', (req, res) => {
res.json({
submissions: ['0'],
});
});
router.get('/:id/submissions', getAssignmentsSubmissionsHandler);
router.get('/:id/questions', (req, res) => {
res.json({