diff --git a/backend/package.json b/backend/package.json index 7b03d8f6..88684af8 100644 --- a/backend/package.json +++ b/backend/package.json @@ -18,6 +18,8 @@ "@mikro-orm/postgresql": "^6.4.6", "@mikro-orm/reflection": "^6.4.6", "@types/js-yaml": "^4.0.9", + "@mikro-orm/sqlite": "^6.4.6", + "@mikro-orm/reflection": "^6.4.6", "dotenv": "^16.4.7", "express": "^5.0.1", "js-yaml": "^4.1.0" diff --git a/backend/src/app.ts b/backend/src/app.ts index 90a6f45b..b3624fc3 100644 --- a/backend/src/app.ts +++ b/backend/src/app.ts @@ -2,9 +2,18 @@ import express, { Express, Response } from 'express'; import initORM from './orm.js'; import themeRoutes from './routes/themes.js'; +import studentRouter from './routes/student'; +import groupRouter from './routes/group'; +import assignmentRouter from './routes/assignment'; +import submissionRouter from './routes/submission'; +import classRouter from './routes/class'; +import questionRouter from './routes/question'; +import loginRouter from './routes/login'; + const app: Express = express(); const port: string | number = process.env.PORT || 3000; + // TODO Replace with Express routes app.get('/', (_, res: Response) => { res.json({ @@ -12,6 +21,14 @@ app.get('/', (_, res: Response) => { }); }); +app.use('/student', studentRouter); +app.use('/group', groupRouter); +app.use('/assignment', assignmentRouter); +app.use('/submission', submissionRouter); +app.use('/class', classRouter); +app.use('/question', questionRouter); +app.use('/login', loginRouter); + app.use('/theme', themeRoutes); async function startServer() { diff --git a/backend/src/routes/assignment.ts b/backend/src/routes/assignment.ts new file mode 100644 index 00000000..fcb6e9da --- /dev/null +++ b/backend/src/routes/assignment.ts @@ -0,0 +1,54 @@ +import express from 'express' +const router = express.Router(); + +// root endpoint used to search objects +router.get('/', (req, res) => { + res.json({ + assignments: [ + '0', + '1', + ] + }); +}); + +// information about an assignment with id 'id' +router.get('/:id', (req, res) => { + res.json({ + id: req.params.id, + title: 'Dit is een test assignment', + description: 'Een korte beschrijving', + groups: [ '0' ], + learningPath: '0', + class: '0', + links: { + self: `${req.baseUrl}/${req.params.id}`, + submissions: `${req.baseUrl}/${req.params.id}`, + }, + }); +}) + +router.get('/:id/submissions', (req, res) => { + res.json({ + submissions: [ + '0' + ], + }); +}); + +router.get('/:id/groups', (req, res) => { + res.json({ + groups: [ + '0' + ], + }); +}); + +router.get('/:id/questions', (req, res) => { + res.json({ + questions: [ + '0' + ], + }); +}); + +export default router \ No newline at end of file diff --git a/backend/src/routes/class.ts b/backend/src/routes/class.ts new file mode 100644 index 00000000..e554a7f2 --- /dev/null +++ b/backend/src/routes/class.ts @@ -0,0 +1,55 @@ +import express from 'express' +const router = express.Router(); + +// root endpoint used to search objects +router.get('/', (req, res) => { + res.json({ + classes: [ + '0', + '1', + ] + }); +}); + +// information about an class with id 'id' +router.get('/:id', (req, res) => { + res.json({ + id: req.params.id, + displayName: 'Klas 4B', + teachers: [ '0' ], + students: [ '0' ], + joinRequests: [ '0' ], + links: { + self: `${req.baseUrl}/${req.params.id}`, + classes: `${req.baseUrl}/${req.params.id}/invitations`, + questions: `${req.baseUrl}/${req.params.id}/assignments`, + students: `${req.baseUrl}/${req.params.id}/students`, + } + }); +}) + +router.get('/:id/invitations', (req, res) => { + res.json({ + invitations: [ + '0' + ], + }); +}) + +router.get('/:id/assignments', (req, res) => { + res.json({ + assignments: [ + '0' + ], + }); +}) + +router.get('/:id/students', (req, res) => { + res.json({ + students: [ + '0' + ], + }); +}) + +export default router \ No newline at end of file diff --git a/backend/src/routes/group.ts b/backend/src/routes/group.ts new file mode 100644 index 00000000..e55dddd1 --- /dev/null +++ b/backend/src/routes/group.ts @@ -0,0 +1,34 @@ +import express from 'express' +const router = express.Router(); + +// root endpoint used to search objects +router.get('/', (req, res) => { + res.json({ + groups: [ + '0', + '1', + ] + }); +}); + +// information about a group (members, ... [TODO DOC]) +router.get('/:id', (req, res) => { + res.json({ + id: req.params.id, + assignment: '0', + students: [ '0' ], + submissions: [ '0' ], + // reference to other endpoint + // should be less hardcoded + questions: `/group/${req.params.id}/question`, + }); +}) + +// the list of questions a group has made +router.get('/:id/question', (req, res) => { + res.json({ + questions: [ '0' ], + }); +}) + +export default router \ No newline at end of file diff --git a/backend/src/routes/login.ts b/backend/src/routes/login.ts new file mode 100644 index 00000000..550e6d93 --- /dev/null +++ b/backend/src/routes/login.ts @@ -0,0 +1,14 @@ +import express from 'express' +const router = express.Router(); + +// returns login paths for IDP +router.get('/', (req, res) => { + res.json({ + // dummy variables, needs to be changed + // with IDP endpoints + leerkracht: '/login-leerkracht', + leerling: '/login-leerling', + }); +}) + +export default router \ No newline at end of file diff --git a/backend/src/routes/question.ts b/backend/src/routes/question.ts new file mode 100644 index 00000000..25d168b7 --- /dev/null +++ b/backend/src/routes/question.ts @@ -0,0 +1,38 @@ +import express from 'express' +const router = express.Router(); + +// root endpoint used to search objects +router.get('/', (req, res) => { + res.json({ + questions: [ + '0', + '1', + ] + }); +}); + +// information about an question with id 'id' +router.get('/:id', (req, res) => { + res.json({ + id: req.params.id, + student: '0', + group: '0', + time: new Date(2025, 1, 1), + content: 'Zijn alle gehele getallen groter dan 2 gelijk aan de som van 2 priemgetallen????', + learningObject: '0', + links: { + self: `${req.baseUrl}/${req.params.id}`, + answers: `${req.baseUrl}/${req.params.id}/answers`, + } + }); +}) + +router.get('/:id/answers', (req, res) => { + res.json({ + answers: [ + '0' + ], + }) +}) + +export default router \ No newline at end of file diff --git a/backend/src/routes/student.ts b/backend/src/routes/student.ts new file mode 100644 index 00000000..a11c1fbc --- /dev/null +++ b/backend/src/routes/student.ts @@ -0,0 +1,59 @@ +import express from 'express' +const router = express.Router(); + +// root endpoint used to search objects +router.get('/', (req, res) => { + res.json({ + students: [ + '0', + '1', + ] + }); +}); + +// information about a student's profile +router.get('/:id', (req, res) => { + res.json({ + id: req.params.id, + firstName: 'Jimmy', + lastName: 'Faster', + username: 'JimmyFaster2', + 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`, + }, + }); +}); + +// the list of classes a student is in +router.get('/:id/classes', (req, res) => { + res.json({ + classes: [ '0' ], + }); +}) + +// the list of submissions a student has made +router.get('/:id/submissions', (req, res) => { + res.json({ + submissions: [ '0' ], + }); +}) + + +// the list of assignments a student has +router.get('/:id/assignments', (req, res) => { + res.json({ + assignments: [ '0' ], + }); +}) + +// the list of groups a student is in +router.get('/:id/groups', (req, res) => { + res.json({ + groups: [ '0' ], + }); +}) + +export default router \ No newline at end of file diff --git a/backend/src/routes/submission.ts b/backend/src/routes/submission.ts new file mode 100644 index 00000000..8d09cf8e --- /dev/null +++ b/backend/src/routes/submission.ts @@ -0,0 +1,26 @@ +import express from 'express' +const router = express.Router(); + +// root endpoint used to search objects +router.get('/', (req, res) => { + res.json({ + submissions: [ + '0', + '1', + ] + }); +}); + +// information about an submission with id 'id' +router.get('/:id', (req, res) => { + res.json({ + id: req.params.id, + student: '0', + group: '0', + time: new Date(2025, 1, 1), + content: 'Wortel 2 is rationeel', + learningObject: '0', + }); +}) + +export default router \ No newline at end of file diff --git a/backend/src/routes/teacher.ts b/backend/src/routes/teacher.ts new file mode 100644 index 00000000..37b3b04b --- /dev/null +++ b/backend/src/routes/teacher.ts @@ -0,0 +1,58 @@ +import express from 'express' +const router = express.Router(); + +// root endpoint used to search objects +router.get('/', (req, res) => { + res.json({ + teachers: [ + '0', + '1', + ] + }); +}); + +// information about a teacher +router.get('/:id', (req, res) => { + res.json({ + id: req.params.id, + firstName: 'John', + lastName: 'Doe', + username: 'JohnDoe1', + links: { + self: `${req.baseUrl}/${req.params.id}`, + classes: `${req.baseUrl}/${req.params.id}/classes`, + questions: `${req.baseUrl}/${req.params.id}/questions`, + invitations: `${req.baseUrl}/${req.params.id}/invitations`, + }, + }); +}) + +// the questions students asked a teacher +router.get('/:id/questions', (req, res) => { + res.json({ + questions: [ + '0' + ], + }); +}); + +// invitations to other classes a teacher received +router.get('/:id/invitations', (req, res) => { + res.json({ + invitations: [ + '0' + ], + }); +}); + +// a list with ids of classes a teacher is in +router.get('/:id/classes', (req, res) => { + res.json({ + classes: [ + '0' + ], + }); +}); + + +export default router \ No newline at end of file