feat: class/:id service en controller laag geimplementeerd (BEVAT NOG BUG)

This commit is contained in:
Adriaan Jacquet 2025-03-04 16:32:59 +01:00
parent ceef74f1af
commit e9d9e52f9d
5 changed files with 60 additions and 33 deletions

View file

@ -0,0 +1,29 @@
import { Request, Response } from 'express';
import { getClass } from '../services/class';
export async function getClassHandler(
req: Request,
res: Response,
): Promise<void> {
try {
const classId = req.params.id;
const cls = await getClass(classId);
if (!cls) {
res.status(404).json({ error: "Student not found" });
return;
} else {
cls.endpoints = {
self: `${req.baseUrl}/${req.params.id}`,
invitations: `${req.baseUrl}/${req.params.id}/invitations`,
assignments: `${req.baseUrl}/${req.params.id}/assignments`,
students: `${req.baseUrl}/${req.params.id}/students`,
}
res.json(cls);
}
} catch (error) {
console.error('Error fetching learning objects:', error);
res.status(500).json({ error: 'Internal server error' });
}
}