fix: backend controllers gehomologeerd #130

This commit is contained in:
Adriaan Jacquet 2025-03-22 11:41:52 +01:00
parent 30ec73a88d
commit 32a3bb0dd6
10 changed files with 75 additions and 194 deletions

View file

@ -9,13 +9,8 @@ import {
getStudentGroups,
getStudentSubmissions,
} from '../services/students.js';
import { ClassDTO } from '../interfaces/class.js';
import { getAllAssignments } from '../services/assignments.js';
import { getUserHandler } from './users.js';
import { Student } from '../entities/users/student.entity.js';
import { StudentDTO } from '../interfaces/student.js';
import { getStudentRepository } from '../data/repositories.js';
import { UserDTO } from '../interfaces/user.js';
// TODO: accept arguments (full, ...)
// TODO: endpoints
@ -31,7 +26,7 @@ export async function getAllStudentsHandler(req: Request, res: Response): Promis
return;
}
res.status(201).json(students);
res.json({ students: students });
}
export async function getStudentHandler(req: Request, res: Response): Promise<void> {
@ -51,7 +46,7 @@ export async function getStudentHandler(req: Request, res: Response): Promise<vo
return;
}
res.status(201).json(user);
res.json(user);
}
export async function createStudentHandler(req: Request, res: Response) {
@ -88,25 +83,14 @@ export async function deleteStudentHandler(req: Request, res: Response) {
}
export async function getStudentClassesHandler(req: Request, res: Response): Promise<void> {
try {
const full = req.query.full === 'true';
const username = req.params.id;
const full = req.query.full === 'true';
const username = req.params.id;
const classes = await getStudentClasses(username, full);
const classes = await getStudentClasses(username, full);
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' });
}
res.json({
classes: classes,
});
}
// TODO