feat: endpoints voor /, /:id en /:id/students in routes/class.ts zijn geimplementeerd

This commit is contained in:
Adriaan Jacquet 2025-03-05 16:31:27 +01:00
parent 123fdf0fa1
commit 241fe0103f
7 changed files with 95 additions and 34 deletions

View file

@ -1,5 +1,18 @@
import { Request, Response } from 'express';
import { getClass } from '../services/class';
import { getAllClasses, getClass, getClassStudents } from '../services/class';
import { ClassDTO } from '../interfaces/classes';
export async function getAllClassesHandler(
req: Request,
res: Response,
): Promise<void> {
const full = req.query.full === "true";
const classes = await getAllClasses(full);
res.json({
classes: classes
});
}
export async function getClassHandler(
req: Request,
@ -26,4 +39,18 @@ export async function getClassHandler(
console.error('Error fetching learning objects:', error);
res.status(500).json({ error: 'Internal server error' });
}
}
export async function getClassStudentsHandler(
req: Request,
res: Response,
): Promise<void> {
const classId = req.params.id;
const full = req.query.full === "true";
const students = await getClassStudents(classId, full);
res.json({
students: students,
});
}

View file

@ -1,17 +1,18 @@
import { Request, Response } from 'express';
import { getStudent, getStudentClasses, getStudentClassIds } from '../services/students';
import { getAllStudents, getStudent, getStudentClasses, getStudentClassIds } from '../services/students';
import { ClassDTO } from '../interfaces/classes';
// TODO: accept arguments (full, ...)
// TODO: endpoints
export async function getAllStudentsHandler (
req: Request,
res: Response,
): Promise<void> {
try {
const students = await getAllStudents();
res.json({
students: [
'0',
'1',
]
students: students
});
} catch (error) {
console.error('Error fetching learning objects:', error);