feat: alle assignments en student's assignments geimplementeerd
This commit is contained in:
parent
7e051d412a
commit
e0a5596994
6 changed files with 77 additions and 24 deletions
|
@ -1,12 +1,26 @@
|
|||
import { Request, Response } from 'express'
|
||||
import { getAssignment } from '../services/assignments';
|
||||
import { getAllAssignments, getAssignment } from '../services/assignments';
|
||||
|
||||
// typescript is annoywith with parameter forwarding from class.ts
|
||||
// typescript is annoy with with parameter forwarding from class.ts
|
||||
interface AssignmentParams {
|
||||
classid: string;
|
||||
id: string;
|
||||
}
|
||||
|
||||
export async function getAllAssignmentsHandler(
|
||||
req: Request<AssignmentParams>,
|
||||
res: Response,
|
||||
): Promise<void> {
|
||||
const classid = req.params.classid;
|
||||
const full = req.query.full === 'true';
|
||||
|
||||
const assignments = await getAllAssignments(classid, full);
|
||||
|
||||
res.json({
|
||||
assignments: assignments,
|
||||
});
|
||||
}
|
||||
|
||||
export async function getAssignmentHandler(
|
||||
req: Request<AssignmentParams>,
|
||||
res: Response,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { Request, Response } from 'express';
|
||||
import { getAllStudents, getStudent, getStudentClasses, getStudentClassIds } from '../services/students';
|
||||
import { ClassDTO } from '../interfaces/classes';
|
||||
import { getAllAssignments } from '../services/assignments';
|
||||
|
||||
// TODO: accept arguments (full, ...)
|
||||
// TODO: endpoints
|
||||
|
@ -72,4 +73,23 @@ export async function getStudentClassesHandler (
|
|||
console.error('Error fetching learning objects:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
}
|
||||
|
||||
// Might not be fully correct depending on if
|
||||
// a class has an assignment, that all students
|
||||
// have this assignment.
|
||||
export async function getStudentAssignmentsHandler(
|
||||
req: Request,
|
||||
res: Response,
|
||||
): Promise<void> {
|
||||
const full = req.query.full === 'true';
|
||||
const username = req.params.id;
|
||||
|
||||
const classes = await getStudentClasses(username);
|
||||
|
||||
const assignments = (await Promise.all(classes.map(async cls => await getAllAssignments(cls.id, full)))).flat();
|
||||
|
||||
res.json({
|
||||
assignments: assignments
|
||||
});
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
import { Assignment } from "../entities/assignments/assignment.entity";
|
||||
import { Class } from "../entities/classes/class.entity";
|
||||
import { GroupDTO } from "./groups";
|
||||
import { GroupDTO, mapToGroupDTO } from "./groups";
|
||||
|
||||
export interface AssignmentDTO {
|
||||
id: number,
|
||||
|
@ -9,17 +9,29 @@ export interface AssignmentDTO {
|
|||
description: string,
|
||||
learningPath: string,
|
||||
language: string,
|
||||
groups?: GroupDTO[], // TODO
|
||||
groups?: GroupDTO[] | string[], // TODO
|
||||
}
|
||||
|
||||
export function mapToAssignmentDTO(assignment: Assignment, cls: Class): AssignmentDTO {
|
||||
export function mapToAssignmentDTOId(assignment: Assignment): AssignmentDTO {
|
||||
return {
|
||||
id: assignment.id,
|
||||
class: cls.classId,
|
||||
class: assignment.within.classId,
|
||||
title: assignment.title,
|
||||
description: assignment.description,
|
||||
learningPath: assignment.learningPathHruid,
|
||||
language: assignment.learningPathLanguage,
|
||||
//groups: assignment.groups.map(mapToGroupDTO),
|
||||
// groups: assignment.groups.map(group => group.groupNumber),
|
||||
}
|
||||
}
|
||||
|
||||
export function mapToAssignmentDTO(assignment: Assignment): AssignmentDTO {
|
||||
return {
|
||||
id: assignment.id,
|
||||
class: assignment.within.classId,
|
||||
title: assignment.title,
|
||||
description: assignment.description,
|
||||
learningPath: assignment.learningPathHruid,
|
||||
language: assignment.learningPathLanguage,
|
||||
// groups: assignment.groups.map(mapToGroupDTO),
|
||||
};
|
||||
}
|
|
@ -1,18 +1,11 @@
|
|||
import express from 'express'
|
||||
import { getAssignmentHandler } from '../controllers/assignments';
|
||||
import { getAllAssignmentsHandler, getAssignmentHandler } from '../controllers/assignments';
|
||||
import groupRouter from './group.js';
|
||||
|
||||
const router = express.Router({ mergeParams: true });
|
||||
|
||||
// root endpoint used to search objects
|
||||
router.get('/', (req, res) => {
|
||||
res.json({
|
||||
assignments: [
|
||||
'0',
|
||||
'1',
|
||||
]
|
||||
});
|
||||
});
|
||||
router.get('/', getAllAssignmentsHandler);
|
||||
|
||||
// information about an assignment with id 'id'
|
||||
router.get('/:id', getAssignmentHandler);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import express from 'express'
|
||||
import { getAllStudentsHandler, getStudentClassesHandler, getStudentHandler } from '../controllers/students';
|
||||
import { getAllStudentsHandler, getStudentAssignmentsHandler, getStudentClassesHandler, getStudentHandler } from '../controllers/students';
|
||||
const router = express.Router();
|
||||
|
||||
// root endpoint used to search objects
|
||||
|
@ -20,11 +20,7 @@ router.get('/:id/submissions', (req, res) => {
|
|||
|
||||
|
||||
// the list of assignments a student has
|
||||
router.get('/:id/assignments', (req, res) => {
|
||||
res.json({
|
||||
assignments: [ '0' ],
|
||||
});
|
||||
})
|
||||
router.get('/:id/assignments', getStudentAssignmentsHandler);
|
||||
|
||||
// the list of groups a student is in
|
||||
router.get('/:id/groups', (req, res) => {
|
||||
|
|
|
@ -1,5 +1,23 @@
|
|||
import { getAssignmentRepository, getClassRepository } from "../data/repositories";
|
||||
import { AssignmentDTO, mapToAssignmentDTO } from "../interfaces/assignments";
|
||||
import { AssignmentDTO, mapToAssignmentDTO, mapToAssignmentDTOId } from "../interfaces/assignments";
|
||||
|
||||
export async function getAllAssignments(classid: string, full: boolean): Promise<AssignmentDTO[]> {
|
||||
const classRepository = getClassRepository();
|
||||
const cls = await classRepository.findById(classid);
|
||||
|
||||
if (!cls) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const assignmentRepository = getAssignmentRepository();
|
||||
const assignments = await assignmentRepository.findAllAssignmentsInClass(cls);
|
||||
|
||||
if (full) {
|
||||
return assignments.map(mapToAssignmentDTO);
|
||||
}
|
||||
|
||||
return assignments.map(mapToAssignmentDTOId);
|
||||
}
|
||||
|
||||
export async function getAssignment(classid: string, id: number): Promise<AssignmentDTO | null> {
|
||||
const classRepository = getClassRepository();
|
||||
|
@ -16,5 +34,5 @@ export async function getAssignment(classid: string, id: number): Promise<Assign
|
|||
return null;
|
||||
}
|
||||
|
||||
return mapToAssignmentDTO(assignment, cls);
|
||||
return mapToAssignmentDTO(assignment);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue