import { Request, Response } from 'express'; import { getAllClasses, getClass, getClassStudents, getClassStudentsIds, getClassTeacherInvitations } from '../services/class.js'; import { ClassDTO } from '../interfaces/classes.js'; export async function getAllClassesHandler( req: Request, res: Response, ): Promise { const full = req.query.full === "true"; const classes = await getAllClasses(full); res.json({ classes: classes }); } export async function getClassHandler( req: Request, res: Response, ): Promise { 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' }); } } export async function getClassStudentsHandler( req: Request, res: Response, ): Promise { const classId = req.params.id; const full = req.query.full === "true"; let students = full ? await getClassStudents(classId) : await getClassStudentsIds(classId); res.json({ students: students, }); } export async function getTeacherInvitationsHandler( req: Request, res: Response, ): Promise { const classId = req.params.id; const full = req.query.full === "true"; // TODO: not implemented yet const invitations = await getClassTeacherInvitations(classId, full); res.json({ invitations: invitations, }); }