feat: 'full' query toegevoegd aan alle endpoints waar nodig
This commit is contained in:
parent
8268031096
commit
d65bdd4fb4
11 changed files with 80 additions and 63 deletions
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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> {
|
||||
|
|
|
@ -9,12 +9,6 @@ export interface ClassDTO {
|
|||
teachers: string[];
|
||||
students: string[];
|
||||
joinRequests: string[];
|
||||
endpoints?: {
|
||||
self: string;
|
||||
invitations: string;
|
||||
assignments: string;
|
||||
students: string;
|
||||
};
|
||||
}
|
||||
|
||||
export function mapToClassDTO(cls: Class): ClassDTO {
|
||||
|
|
|
@ -17,6 +17,14 @@ export interface SubmissionDTO {
|
|||
content: string;
|
||||
}
|
||||
|
||||
export interface SubmissionDTOId {
|
||||
learningObjectHruid: string;
|
||||
learningObjectLanguage: Language;
|
||||
learningObjectVersion: number;
|
||||
|
||||
submissionNumber?: number;
|
||||
}
|
||||
|
||||
export function mapToSubmissionDTO(submission: Submission): SubmissionDTO {
|
||||
return {
|
||||
learningObjectHruid: submission.learningObjectHruid,
|
||||
|
@ -31,6 +39,16 @@ export function mapToSubmissionDTO(submission: Submission): SubmissionDTO {
|
|||
};
|
||||
}
|
||||
|
||||
export function mapToSubmissionDTOId(submission: Submission): SubmissionDTOId {
|
||||
return {
|
||||
learningObjectHruid: submission.learningObjectHruid,
|
||||
learningObjectLanguage: submission.learningObjectLanguage,
|
||||
learningObjectVersion: submission.learningObjectVersion,
|
||||
|
||||
submissionNumber: submission.submissionNumber,
|
||||
}
|
||||
}
|
||||
|
||||
export function mapToSubmission(submissionDTO: SubmissionDTO): Submission {
|
||||
const submission = new Submission();
|
||||
submission.learningObjectHruid = submissionDTO.learningObjectHruid;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { getAssignmentRepository, getClassRepository, getGroupRepository, getSubmissionRepository } from '../data/repositories.js';
|
||||
import { Assignment } from '../entities/assignments/assignment.entity.js';
|
||||
import { AssignmentDTO, mapToAssignment, mapToAssignmentDTO, mapToAssignmentDTOId } from '../interfaces/assignment.js';
|
||||
import { mapToSubmissionDTO, SubmissionDTO } from '../interfaces/submission.js';
|
||||
import { mapToSubmissionDTO, mapToSubmissionDTOId, SubmissionDTO, SubmissionDTOId } from '../interfaces/submission.js';
|
||||
|
||||
export async function getAllAssignments(classid: string, full: boolean): Promise<AssignmentDTO[]> {
|
||||
const classRepository = getClassRepository();
|
||||
|
@ -60,7 +60,7 @@ export async function getAssignment(classid: string, id: number): Promise<Assign
|
|||
return mapToAssignmentDTO(assignment);
|
||||
}
|
||||
|
||||
export async function getAssignmentsSubmissions(classid: string, assignmentNumber: number): Promise<SubmissionDTO[]> {
|
||||
export async function getAssignmentsSubmissions(classid: string, assignmentNumber: number, full: boolean): Promise<SubmissionDTO[] | SubmissionDTOId[]> {
|
||||
const classRepository = getClassRepository();
|
||||
const cls = await classRepository.findById(classid);
|
||||
|
||||
|
@ -81,5 +81,9 @@ export async function getAssignmentsSubmissions(classid: string, assignmentNumbe
|
|||
const submissionRepository = getSubmissionRepository();
|
||||
const submissions = (await Promise.all(groups.map((group) => submissionRepository.findAllSubmissionsForGroup(group)))).flat();
|
||||
|
||||
return submissions.map(mapToSubmissionDTO);
|
||||
if (full) {
|
||||
return submissions.map(mapToSubmissionDTO);
|
||||
}
|
||||
|
||||
return submissions.map(mapToSubmissionDTOId);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import {
|
|||
} from '../data/repositories.js';
|
||||
import { Group } from '../entities/assignments/group.entity.js';
|
||||
import { GroupDTO, mapToGroupDTO, mapToGroupDTOId } from '../interfaces/group.js';
|
||||
import { mapToSubmissionDTO, SubmissionDTO } from '../interfaces/submission.js';
|
||||
import { mapToSubmissionDTO, mapToSubmissionDTOId, SubmissionDTO, SubmissionDTOId } from '../interfaces/submission.js';
|
||||
|
||||
export async function getGroup(classId: string, assignmentNumber: number, groupNumber: number, full: boolean): Promise<GroupDTO | null> {
|
||||
const classRepository = getClassRepository();
|
||||
|
@ -103,7 +103,12 @@ export async function getAllGroups(classId: string, assignmentNumber: number, fu
|
|||
return groups.map(mapToGroupDTOId);
|
||||
}
|
||||
|
||||
export async function getGroupSubmissions(classId: string, assignmentNumber: number, groupNumber: number): Promise<SubmissionDTO[]> {
|
||||
export async function getGroupSubmissions(
|
||||
classId: string,
|
||||
assignmentNumber: number,
|
||||
groupNumber: number,
|
||||
full: boolean
|
||||
): Promise<SubmissionDTO[] | SubmissionDTOId[]> {
|
||||
const classRepository = getClassRepository();
|
||||
const cls = await classRepository.findById(classId);
|
||||
|
||||
|
@ -128,5 +133,9 @@ export async function getGroupSubmissions(classId: string, assignmentNumber: num
|
|||
const submissionRepository = getSubmissionRepository();
|
||||
const submissions = await submissionRepository.findAllSubmissionsForGroup(group);
|
||||
|
||||
return submissions.map(mapToSubmissionDTO);
|
||||
if (full) {
|
||||
return submissions.map(mapToSubmissionDTO);
|
||||
}
|
||||
|
||||
return submissions.map(mapToSubmissionDTOId);
|
||||
}
|
||||
|
|
|
@ -5,19 +5,18 @@ import { AssignmentDTO } from '../interfaces/assignment.js';
|
|||
import { ClassDTO, mapToClassDTO } from '../interfaces/class.js';
|
||||
import { GroupDTO, mapToGroupDTO, mapToGroupDTOId } from '../interfaces/group.js';
|
||||
import { mapToStudent, mapToStudentDTO, StudentDTO } from '../interfaces/student.js';
|
||||
import { mapToSubmissionDTO, SubmissionDTO } from '../interfaces/submission.js';
|
||||
import { mapToSubmissionDTO, mapToSubmissionDTOId, SubmissionDTO, SubmissionDTOId } from '../interfaces/submission.js';
|
||||
import { getAllAssignments } from './assignments.js';
|
||||
import { UserService } from './users.js';
|
||||
|
||||
export async function getAllStudents(): Promise<StudentDTO[]> {
|
||||
export async function getAllStudents(full: boolean): Promise<StudentDTO[] | string[]> {
|
||||
const studentRepository = getStudentRepository();
|
||||
const users = await studentRepository.findAll();
|
||||
return users.map(mapToStudentDTO);
|
||||
}
|
||||
const students = await studentRepository.findAll();
|
||||
|
||||
export async function getAllStudentIds(): Promise<string[]> {
|
||||
const users = await getAllStudents();
|
||||
return users.map((user) => user.username);
|
||||
if (full) {
|
||||
return students.map(mapToStudentDTO);
|
||||
}
|
||||
|
||||
return students.map(student => student.username);
|
||||
}
|
||||
|
||||
export async function getStudent(username: string): Promise<StudentDTO | null> {
|
||||
|
@ -111,7 +110,7 @@ export async function getStudentGroups(username: string, full: boolean): Promise
|
|||
return groups.map(mapToGroupDTOId);
|
||||
}
|
||||
|
||||
export async function getStudentSubmissions(username: string): Promise<SubmissionDTO[]> {
|
||||
export async function getStudentSubmissions(username: string, full: boolean): Promise<SubmissionDTO[] | SubmissionDTOId[]> {
|
||||
const studentRepository = getStudentRepository();
|
||||
const student = await studentRepository.findByUsername(username);
|
||||
|
||||
|
@ -122,5 +121,9 @@ export async function getStudentSubmissions(username: string): Promise<Submissio
|
|||
const submissionRepository = getSubmissionRepository();
|
||||
const submissions = await submissionRepository.findAllSubmissionsForStudent(student);
|
||||
|
||||
return submissions.map(mapToSubmissionDTO);
|
||||
if (full) {
|
||||
return submissions.map(mapToSubmissionDTO);
|
||||
}
|
||||
|
||||
return submissions.map(mapToSubmissionDTOId);
|
||||
}
|
||||
|
|
|
@ -12,16 +12,17 @@ import { StudentDTO } from '../interfaces/student.js';
|
|||
import { mapToQuestionDTO, mapToQuestionId, QuestionDTO, QuestionId } from '../interfaces/question.js';
|
||||
import { mapToUser } from '../interfaces/user.js';
|
||||
import { mapToTeacher, mapToTeacherDTO, TeacherDTO } from '../interfaces/teacher.js';
|
||||
import { teachersOnly } from '../middleware/auth/auth.js';
|
||||
|
||||
export async function getAllTeachers(): Promise<TeacherDTO[]> {
|
||||
export async function getAllTeachers(full: boolean): Promise<TeacherDTO[] | string[]> {
|
||||
const teacherRepository = getTeacherRepository();
|
||||
const users = await teacherRepository.findAll();
|
||||
return users.map(mapToTeacherDTO);
|
||||
}
|
||||
const teachers = await teacherRepository.findAll();
|
||||
|
||||
export async function getAllTeacherIds(): Promise<string[]> {
|
||||
const users = await getAllTeachers();
|
||||
return users.map((user) => user.username);
|
||||
if (full) {
|
||||
return teachers.map(mapToTeacherDTO);
|
||||
}
|
||||
|
||||
return teachers.map(teacher => teacher.username);
|
||||
}
|
||||
|
||||
export async function getTeacher(username: string): Promise<TeacherDTO | null> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue