feat: controller en service laag toegevoegd voor student/:id/classes

This commit is contained in:
Adriaan Jacquet 2025-03-04 15:50:20 +01:00
parent f5b6a5a604
commit ceef74f1af
6 changed files with 127 additions and 23 deletions

View file

@ -1,13 +1,31 @@
import { Request, Response } from 'express';
import { getStudentById } from "../services/students";
import { getStudent, getStudentClasses, getStudentClassIds } from '../services/students';
import { ClassDTO } from '../interfaces/classes';
export async function getStudent(
export async function getAllStudentsHandler (
req: Request,
res: Response,
): Promise<void> {
try {
res.json({
students: [
'0',
'1',
]
});
} catch (error) {
console.error('Error fetching learning objects:', error);
res.status(500).json({ error: 'Internal server error' });
}
}
export async function getStudentHandler(
req: Request,
res: Response,
): Promise<void> {
try {
const username = req.params.id;
const student = await getStudentById(username);
const student = await getStudent(username);
if (!student) {
res.status(404).json({ error: "Student not found" });
@ -21,7 +39,34 @@ export async function getStudent(
}
res.json(student);
}
} catch (error) {
console.error('Error fetching learning objects:', error);
res.status(500).json({ error: 'Internal server error' });
}
}
export async function getStudentClassesHandler (
req: Request,
res: Response,
): Promise<void> {
try {
const full = req.query.full === 'true';
const username = req.params.id;
let classes: ClassDTO[] | string[];
if (full) classes = await getStudentClasses(username);
else classes = await getStudentClassIds(username);
res.json({
classes: classes,
endpoints: {
self: `${req.baseUrl}/${req.params.id}`,
classes: `${req.baseUrl}/${req.params.id}/invitations`,
questions: `${req.baseUrl}/${req.params.id}/assignments`,
students: `${req.baseUrl}/${req.params.id}/students`,
}
});
} catch (error) {
console.error('Error fetching learning objects:', error);
res.status(500).json({ error: 'Internal server error' });