feat: 'full' query toegevoegd aan alle endpoints waar nodig

This commit is contained in:
Adriaan Jacquet 2025-03-22 13:46:29 +01:00
parent 8268031096
commit d65bdd4fb4
11 changed files with 80 additions and 63 deletions

View file

@ -62,13 +62,15 @@ export async function getAssignmentHandler(req: Request<AssignmentParams>, res:
export async function getAssignmentsSubmissionsHandler(req: Request<AssignmentParams>, res: Response): Promise<void> {
const classid = req.params.classid;
const assignmentNumber = +req.params.id;
const full = req.query.full === 'true';
if (isNaN(assignmentNumber)) {
res.status(400).json({ error: 'Assignment id must be a number' });
return;
}
const submissions = await getAssignmentsSubmissions(classid, assignmentNumber);
const submissions = await getAssignmentsSubmissions(classid, assignmentNumber, full);
res.json({
submissions: submissions,

View file

@ -32,26 +32,15 @@ export async function createClassHandler(req: Request, res: Response): Promise<v
}
export async function getClassHandler(req: Request, res: Response): Promise<void> {
try {
const classId = req.params.id;
const cls = await getClass(classId);
const classId = req.params.id;
const cls = await getClass(classId);
if (!cls) {
res.status(404).json({ error: 'Class not found' });
return;
}
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' });
if (!cls) {
res.status(404).json({ error: 'Class not found' });
return;
}
res.json(cls);
}
export async function getClassStudentsHandler(req: Request, res: Response): Promise<void> {
@ -67,7 +56,7 @@ export async function getClassStudentsHandler(req: Request, res: Response): Prom
export async function getTeacherInvitationsHandler(req: Request, res: Response): Promise<void> {
const classId = req.params.id;
const full = req.query.full === 'true'; // TODO: not implemented yet
const full = req.query.full === 'true';
const invitations = await getClassTeacherInvitations(classId, full);

View file

@ -71,7 +71,7 @@ export async function createGroupHandler(req: Request, res: Response): Promise<v
export async function getGroupSubmissionsHandler(req: Request, res: Response): Promise<void> {
const classId = req.params.classid;
// Const full = req.query.full === 'true';
const full = req.query.full === 'true';
const assignmentId = +req.params.assignmentid;
@ -87,7 +87,7 @@ export async function getGroupSubmissionsHandler(req: Request, res: Response): P
return;
}
const submissions = await getGroupSubmissions(classId, assignmentId, groupId);
const submissions = await getGroupSubmissions(classId, assignmentId, groupId, full);
res.json({
submissions: submissions,

View file

@ -17,9 +17,7 @@ import { getStudentRepository } from '../data/repositories.js';
export async function getAllStudentsHandler(req: Request, res: Response): Promise<void> {
const full = req.query.full === 'true';
const studentRepository = getStudentRepository();
const students: StudentDTO[] | string[] = full ? await getAllStudents() : await getAllStudents();
const students = await getAllStudents(full);
if (!students) {
res.status(404).json({ error: `Student not found.` });
@ -121,8 +119,9 @@ export async function getStudentGroupsHandler(req: Request, res: Response): Prom
export async function getStudentSubmissionsHandler(req: Request, res: Response): Promise<void> {
const username = req.params.id;
const full = req.query.full === 'true';
const submissions = await getStudentSubmissions(username);
const submissions = await getStudentSubmissions(username, full);
res.json({
submissions: submissions,

View file

@ -14,16 +14,14 @@ import { getTeacherRepository } from '../data/repositories.js';
export async function getAllTeachersHandler(req: Request, res: Response): Promise<void> {
const full = req.query.full === 'true';
const teacherRepository = getTeacherRepository();
const teachers: TeacherDTO[] | string[] = full ? await getAllTeachers() : await getAllTeachers();
const teachers = await getAllTeachers(full);
if (!teachers) {
res.status(404).json({ error: `Teacher not found.` });
return;
}
res.status(201).json({ teachers: teachers });
res.json({ teachers: teachers });
}
export async function getTeacherHandler(req: Request, res: Response): Promise<void> {
@ -38,12 +36,12 @@ export async function getTeacherHandler(req: Request, res: Response): Promise<vo
if (!user) {
res.status(404).json({
error: `User '${username}' not found.`,
error: `Teacher '${username}' not found.`,
});
return;
}
res.status(201).json(user);
res.json(user);
}
export async function createTeacherHandler(req: Request, res: Response) {
@ -96,7 +94,7 @@ export async function getTeacherClassHandler(req: Request, res: Response): Promi
const classes = await getClassesByTeacher(username, full);
res.status(201).json({ classes: classes });
res.json({ classes: classes });
}
export async function getTeacherStudentHandler(req: Request, res: Response): Promise<void> {