feat: service en controller laag voor getStudent geimplementeerd
This commit is contained in:
parent
8c22b72b22
commit
f5b6a5a604
5 changed files with 459 additions and 2917 deletions
29
backend/src/controllers/students.ts
Normal file
29
backend/src/controllers/students.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
import { Request, Response } from 'express';
|
||||
import { getStudentById } from "../services/students";
|
||||
|
||||
export async function getStudent(
|
||||
req: Request,
|
||||
res: Response,
|
||||
): Promise<void> {
|
||||
try {
|
||||
const username = req.params.id;
|
||||
const student = await getStudentById(username);
|
||||
|
||||
if (!student) {
|
||||
res.status(404).json({ error: "Student not found" });
|
||||
return;
|
||||
} else {
|
||||
student.endpoints = {
|
||||
classes: `/student/${req.params.id}/classes`,
|
||||
questions: `/student/${req.params.id}/submissions`,
|
||||
invitations: `/student/${req.params.id}/assignments`,
|
||||
groups: `/student/${req.params.id}/groups`,
|
||||
}
|
||||
res.json(student);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error fetching learning objects:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue