feat: class/:id service en controller laag geimplementeerd (BEVAT NOG BUG)
This commit is contained in:
parent
ceef74f1af
commit
e9d9e52f9d
5 changed files with 60 additions and 33 deletions
29
backend/src/controllers/classes.ts
Normal file
29
backend/src/controllers/classes.ts
Normal 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' });
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue