From 2318d5631668814a66225c365e90276ad7a4eb38 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stef=20Oss=C3=A9?=
Date: Tue, 9 Apr 2024 17:22:25 +0200
Subject: [PATCH 01/90] Created files
---
.../components/authentication/RequireAuth.tsx | 2 +-
frontend/src/dataloaders/LoginLoader.ts | 2 +-
frontend/src/dataloaders/SharedFunctions.ts | 2 +-
frontend/src/main.tsx | 2 ++
frontend/src/pages/Test.tsx | 12 ++++++++++
frontend/src/pages/login/LoginScreen.tsx | 2 +-
frontend/src/pages/root.tsx | 8 +++----
frontend/src/utils/ApiInterfaces.ts | 8 +++----
frontend/src/utils/{ => api}/ApiFetch.ts | 2 +-
frontend/src/utils/api/Groups.ts | 23 +++++++++++++++++++
frontend/src/utils/api/Login.ts | 0
frontend/src/utils/api/Project.ts | 0
frontend/src/utils/api/Student.ts | 0
frontend/src/utils/api/Subject.ts | 0
frontend/src/utils/api/Submission.ts | 0
frontend/src/utils/api/Teacher.ts | 0
frontend/src/utils/api/User.ts | 0
17 files changed, 50 insertions(+), 13 deletions(-)
create mode 100644 frontend/src/pages/Test.tsx
rename frontend/src/utils/{ => api}/ApiFetch.ts (91%)
create mode 100644 frontend/src/utils/api/Groups.ts
create mode 100644 frontend/src/utils/api/Login.ts
create mode 100644 frontend/src/utils/api/Project.ts
create mode 100644 frontend/src/utils/api/Student.ts
create mode 100644 frontend/src/utils/api/Subject.ts
create mode 100644 frontend/src/utils/api/Submission.ts
create mode 100644 frontend/src/utils/api/Teacher.ts
create mode 100644 frontend/src/utils/api/User.ts
diff --git a/frontend/src/components/authentication/RequireAuth.tsx b/frontend/src/components/authentication/RequireAuth.tsx
index 7841130b..3491ea11 100644
--- a/frontend/src/components/authentication/RequireAuth.tsx
+++ b/frontend/src/components/authentication/RequireAuth.tsx
@@ -10,7 +10,7 @@ const RequireAuth = ({allowedRoles}: Props) => {
const location = useLocation();
if (user) {
return (
- (allowedRoles && user.user_roles.find(role => allowedRoles.includes(role)))
+ (allowedRoles && user.roles.find(role => allowedRoles.includes(role)))
?
:
);
diff --git a/frontend/src/dataloaders/LoginLoader.ts b/frontend/src/dataloaders/LoginLoader.ts
index b504affe..ec7625f6 100644
--- a/frontend/src/dataloaders/LoginLoader.ts
+++ b/frontend/src/dataloaders/LoginLoader.ts
@@ -1,5 +1,5 @@
import {User} from "../utils/ApiInterfaces.ts";
-import apiFetch from "../utils/ApiFetch.ts";
+import apiFetch from "../utils/api/ApiFetch.ts";
export const LOGIN_ROUTER_ID = "login";
diff --git a/frontend/src/dataloaders/SharedFunctions.ts b/frontend/src/dataloaders/SharedFunctions.ts
index 252fbb1a..cbc60806 100644
--- a/frontend/src/dataloaders/SharedFunctions.ts
+++ b/frontend/src/dataloaders/SharedFunctions.ts
@@ -1,5 +1,5 @@
import {CompleteProject, Group, Project, Subject, Submission} from "../utils/ApiInterfaces.ts";
-import apiFetch from "../utils/ApiFetch.ts";
+import apiFetch from "../utils/api/ApiFetch.ts";
export enum teacherStudentRole {
STUDENT = "student",
diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx
index ca0f1260..28d210e7 100644
--- a/frontend/src/main.tsx
+++ b/frontend/src/main.tsx
@@ -25,6 +25,7 @@ import CoursesViewTeacher from "./pages/teacher/CoursesViewTeacher.tsx";
import {CreateProject} from "./pages/teacher/CreateProject.tsx";
import CreateCourse from "./pages/teacher/CreateCourse.tsx";
import projectsTeacherLoader, {PROJECTS_TEACHER_ROUTER_ID} from "./dataloaders/projectsTeacherLoader.ts";
+import Test from "./pages/Test.tsx";
const router = createBrowserRouter(
createRoutesFromElements(
@@ -33,6 +34,7 @@ const router = createBrowserRouter(
} loader={loginLoader}
errorElement={}/>
}/>
+ }/>
{/* Protected routes */}
}>
diff --git a/frontend/src/pages/Test.tsx b/frontend/src/pages/Test.tsx
new file mode 100644
index 00000000..626d973e
--- /dev/null
+++ b/frontend/src/pages/Test.tsx
@@ -0,0 +1,12 @@
+import {projectGroup} from "../utils/api/Groups.ts";
+
+export default function Test () {
+ function clickEvent () {
+ console.log(projectGroup(2))
+ }
+
+ return (
+
Welcome on this test page, click the button below to test te function
+
+
)
+}
\ No newline at end of file
diff --git a/frontend/src/pages/login/LoginScreen.tsx b/frontend/src/pages/login/LoginScreen.tsx
index e407a104..0f9beba1 100644
--- a/frontend/src/pages/login/LoginScreen.tsx
+++ b/frontend/src/pages/login/LoginScreen.tsx
@@ -35,7 +35,7 @@ const ticketLogin = async (ticket: string, setUser: React.Dispatch {
- return (data && data.user_id && data.user_name && data.user_email && data.user_roles);
+ return (data && data.id && data.name && data.email && data.roles);
}
diff --git a/frontend/src/pages/root.tsx b/frontend/src/pages/root.tsx
index a9c2d7b2..ea446625 100644
--- a/frontend/src/pages/root.tsx
+++ b/frontend/src/pages/root.tsx
@@ -2,17 +2,17 @@ import {JSX} from "react";
import useAuth from "../hooks/useAuth.ts";
import {Navigate} from "react-router-dom";
-export const DEBUG: boolean = false; // should always be false on the repo.
+export const DEBUG: boolean = true; // should always be false on the repo.
export default function Root(): JSX.Element {
const {user} = useAuth()
let to: string = "/error"
- if (user?.user_roles.includes('TEACHER')) {
+ if (user?.roles.includes('TEACHER')) {
to = "/teacher";
- } else if (user?.user_roles.includes('STUDENT')) {
+ } else if (user?.roles.includes('STUDENT')) {
to = "/student";
- } else if (user?.user_roles.includes('ADMIN')) {
+ } else if (user?.roles.includes('ADMIN')) {
to = "/admin";
}
diff --git a/frontend/src/utils/ApiInterfaces.ts b/frontend/src/utils/ApiInterfaces.ts
index ff17b611..ef530a5b 100644
--- a/frontend/src/utils/ApiInterfaces.ts
+++ b/frontend/src/utils/ApiInterfaces.ts
@@ -48,8 +48,8 @@ export interface Token {
}
export interface User {
- user_id: number,
- user_name: string,
- user_email: string,
- user_roles: string[]
+ id: number,
+ name: string,
+ email: string,
+ roles: string[]
}
\ No newline at end of file
diff --git a/frontend/src/utils/ApiFetch.ts b/frontend/src/utils/api/ApiFetch.ts
similarity index 91%
rename from frontend/src/utils/ApiFetch.ts
rename to frontend/src/utils/api/ApiFetch.ts
index 19c8d250..e4934a1d 100644
--- a/frontend/src/utils/ApiFetch.ts
+++ b/frontend/src/utils/api/ApiFetch.ts
@@ -1,4 +1,4 @@
-import {DEBUG} from "../pages/root.tsx";
+import {DEBUG} from "../../pages/root.tsx";
const ApiFetch = async (url: string, options?: RequestInit) => {
diff --git a/frontend/src/utils/api/Groups.ts b/frontend/src/utils/api/Groups.ts
new file mode 100644
index 00000000..54bc3af5
--- /dev/null
+++ b/frontend/src/utils/api/Groups.ts
@@ -0,0 +1,23 @@
+import ApiFetch from "./ApiFetch.ts";
+
+export function joinGroup(groupId: number) {
+ void ApiFetch(`/groups/${groupId}/join`,
+ {method: 'POST', headers: {'Content-Type': 'application/json'}});
+}
+
+export function leaveGroup(groupId: number) {
+ void ApiFetch(`/groups/${groupId}/leave`,
+ {method: 'POST', headers: {'Content-Type': 'application/json'}});
+}
+
+export async function listGroupMembers(groupId: number) {
+ let members = await ApiFetch(`/groups/${groupId}/members`,
+ {method: 'GET', headers: {'Content-Type': 'application/json'}});
+ return members;
+}
+
+export function projectGroup(projectId: number) {
+ let group = void ApiFetch(`/projects/${projectId}/group`,
+ {method: 'GET', headers: {'Content-Type': 'application/json'}});
+ return group;
+}
\ No newline at end of file
diff --git a/frontend/src/utils/api/Login.ts b/frontend/src/utils/api/Login.ts
new file mode 100644
index 00000000..e69de29b
diff --git a/frontend/src/utils/api/Project.ts b/frontend/src/utils/api/Project.ts
new file mode 100644
index 00000000..e69de29b
diff --git a/frontend/src/utils/api/Student.ts b/frontend/src/utils/api/Student.ts
new file mode 100644
index 00000000..e69de29b
diff --git a/frontend/src/utils/api/Subject.ts b/frontend/src/utils/api/Subject.ts
new file mode 100644
index 00000000..e69de29b
diff --git a/frontend/src/utils/api/Submission.ts b/frontend/src/utils/api/Submission.ts
new file mode 100644
index 00000000..e69de29b
diff --git a/frontend/src/utils/api/Teacher.ts b/frontend/src/utils/api/Teacher.ts
new file mode 100644
index 00000000..e69de29b
diff --git a/frontend/src/utils/api/User.ts b/frontend/src/utils/api/User.ts
new file mode 100644
index 00000000..e69de29b
From 81deb20f15122f7619437595a133be383bd6c4dd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stef=20Oss=C3=A9?=
Date: Tue, 9 Apr 2024 21:39:56 +0200
Subject: [PATCH 02/90] Functies user, projects, subjects, group, course
---
.../components/authentication/ErrorLogin.tsx | 2 +-
.../{LoginLoader.ts => LoginLoader.tsx} | 2 +-
.../src/dataloaders/ProjectsStudentLoader.ts | 2 +-
frontend/src/dataloaders/SharedFunctions.ts | 2 +-
.../src/dataloaders/projectsTeacherLoader.ts | 2 +-
frontend/src/main.tsx | 6 ++--
frontend/src/pages/Test.tsx | 12 -------
frontend/src/pages/login/LoginScreen.tsx | 27 +++++++-------
frontend/src/utils/{api => }/ApiFetch.ts | 2 +-
frontend/src/utils/InputInterfaces.ts | 9 +++++
frontend/src/utils/api/Groups.ts | 14 +-------
frontend/src/utils/api/Login.ts | 16 +++++++++
frontend/src/utils/api/Project.ts | 36 +++++++++++++++++++
frontend/src/utils/api/Student.ts | 7 ++++
frontend/src/utils/api/Subject.ts | 25 +++++++++++++
frontend/src/utils/api/Teacher.ts | 13 +++++++
frontend/src/utils/api/User.ts | 8 +++++
17 files changed, 139 insertions(+), 46 deletions(-)
rename frontend/src/dataloaders/{LoginLoader.ts => LoginLoader.tsx} (93%)
delete mode 100644 frontend/src/pages/Test.tsx
rename frontend/src/utils/{api => }/ApiFetch.ts (91%)
create mode 100644 frontend/src/utils/InputInterfaces.ts
diff --git a/frontend/src/components/authentication/ErrorLogin.tsx b/frontend/src/components/authentication/ErrorLogin.tsx
index 0ab4aa45..1e0ab292 100644
--- a/frontend/src/components/authentication/ErrorLogin.tsx
+++ b/frontend/src/components/authentication/ErrorLogin.tsx
@@ -1,5 +1,5 @@
import {JSX} from "react";
-import delphi_full from "../../../public/delphi_full.png";
+import delphi_full from "/delphi_full.png";
export default function ErrorLogin(): JSX.Element {
diff --git a/frontend/src/dataloaders/LoginLoader.ts b/frontend/src/dataloaders/LoginLoader.tsx
similarity index 93%
rename from frontend/src/dataloaders/LoginLoader.ts
rename to frontend/src/dataloaders/LoginLoader.tsx
index 9edadd53..7c96b78e 100644
--- a/frontend/src/dataloaders/LoginLoader.ts
+++ b/frontend/src/dataloaders/LoginLoader.tsx
@@ -1,7 +1,7 @@
import {User} from "../utils/ApiInterfaces.ts";
import {Backend_user} from "../utils/BackendInterfaces.ts";
import {mapUser} from "../utils/ApiTypesMapper.ts";
-import apiFetch from "../utils/api/ApiFetch.ts";
+import apiFetch from "../utils/ApiFetch.ts";
export const LOGIN_ROUTER_ID = "login";
diff --git a/frontend/src/dataloaders/ProjectsStudentLoader.ts b/frontend/src/dataloaders/ProjectsStudentLoader.ts
index 43b29101..9e782310 100644
--- a/frontend/src/dataloaders/ProjectsStudentLoader.ts
+++ b/frontend/src/dataloaders/ProjectsStudentLoader.ts
@@ -1,6 +1,6 @@
import {CompleteProject, Group, Submission} from "../utils/ApiInterfaces.ts";
import {getAllProjectsAndSubjects, teacherStudentRole} from "./SharedFunctions.ts";
-import apiFetch from "../utils/api/ApiFetch.ts";
+import apiFetch from "../utils/ApiFetch.ts";
import {Backend_group, Backend_submission} from "../utils/BackendInterfaces.ts";
import {mapGroup, mapSubmission} from "../utils/ApiTypesMapper.ts";
diff --git a/frontend/src/dataloaders/SharedFunctions.ts b/frontend/src/dataloaders/SharedFunctions.ts
index 89c9e2d1..da516496 100644
--- a/frontend/src/dataloaders/SharedFunctions.ts
+++ b/frontend/src/dataloaders/SharedFunctions.ts
@@ -1,7 +1,7 @@
import {Project, properSubject, Subject} from "../utils/ApiInterfaces.ts";
import {mapProjectList, mapSubjectList} from "../utils/ApiTypesMapper.ts";
import {Backend_Project, Backend_Subject} from "../utils/BackendInterfaces.ts";
-import apiFetch from "../utils/api/ApiFetch.ts";
+import apiFetch from "../utils/ApiFetch.ts";
export enum teacherStudentRole {
STUDENT = "student",
diff --git a/frontend/src/dataloaders/projectsTeacherLoader.ts b/frontend/src/dataloaders/projectsTeacherLoader.ts
index a709ecf1..87fedcea 100644
--- a/frontend/src/dataloaders/projectsTeacherLoader.ts
+++ b/frontend/src/dataloaders/projectsTeacherLoader.ts
@@ -1,6 +1,6 @@
import {CompleteProjectTeacher, Group, Submission} from "../utils/ApiInterfaces.ts";
import {getAllProjectsAndSubjects, teacherStudentRole} from "./SharedFunctions.ts";
-import apiFetch from "../utils/api/ApiFetch.ts";
+import apiFetch from "../utils/ApiFetch.ts";
import {Backend_group} from "../utils/BackendInterfaces.ts";
import {mapGroupList} from "../utils/ApiTypesMapper.ts";
diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx
index 982d6dfb..2014e4b9 100644
--- a/frontend/src/main.tsx
+++ b/frontend/src/main.tsx
@@ -12,7 +12,7 @@ import studentLoader, {STUDENT_ROUTER_ID} from "./dataloaders/StudentLoader.ts";
import Unauthorized from "./components/authentication/Unauthorized.tsx";
import teacherLoader, {TEACHER_ROUTER_ID} from "./dataloaders/TeacherLoader.ts";
// import coursesTeacherLoader, {SUBJECT_TEACHER_ROUTER_ID} from "./dataloaders/CoursesTeacherLoader.ts";
-import loginLoader, {LOGIN_ROUTER_ID} from "./dataloaders/LoginLoader.ts";
+import loginLoader, {LOGIN_ROUTER_ID} from "./dataloaders/LoginLoader.tsx";
import ErrorLogin from "./components/authentication/ErrorLogin.tsx";
import ProjectsViewStudent from "./pages/student/ProjectsViewStudent.tsx";
import CoursesViewStudent from "./pages/student/CoursesViewStudent.tsx";
@@ -46,7 +46,7 @@ const router = createBrowserRouter(
}/>
- }>
+ }>
} loader={studentLoader}/>
}
loader={projectsStudentLoader}/>
@@ -54,7 +54,7 @@ const router = createBrowserRouter(
loader={coursesStudentLoader}/>
- }>
+ }>
} loader={teacherLoader}/>
}
loader={projectsTeacherLoader}/>
diff --git a/frontend/src/pages/Test.tsx b/frontend/src/pages/Test.tsx
deleted file mode 100644
index 626d973e..00000000
--- a/frontend/src/pages/Test.tsx
+++ /dev/null
@@ -1,12 +0,0 @@
-import {projectGroup} from "../utils/api/Groups.ts";
-
-export default function Test () {
- function clickEvent () {
- console.log(projectGroup(2))
- }
-
- return (
-
Welcome on this test page, click the button below to test te function
-
- )
-}
\ No newline at end of file
diff --git a/frontend/src/pages/login/LoginScreen.tsx b/frontend/src/pages/login/LoginScreen.tsx
index 7b9ec838..f02eea18 100644
--- a/frontend/src/pages/login/LoginScreen.tsx
+++ b/frontend/src/pages/login/LoginScreen.tsx
@@ -1,10 +1,10 @@
import React, {JSX, useEffect} from "react";
import {Navigate, useLocation, useRouteLoaderData} from 'react-router-dom';
import useAuth from "../../hooks/useAuth.ts";
-import loginLoader, {LOGIN_ROUTER_ID, loginLoaderObject} from "../../dataloaders/LoginLoader.ts";
+import loginLoader, {LOGIN_ROUTER_ID, loginLoaderObject} from "../../dataloaders/LoginLoader.tsx";
import LoginForm from "../../components/authentication/LoginForm.tsx";
-import {DEBUG} from "../root.tsx";
import {Token, User} from "../../utils/ApiInterfaces.ts";
+import {post_ticket} from "../../utils/api/Login.ts";
interface location_type {
search?: { ticket?: string },
@@ -13,17 +13,12 @@ interface location_type {
}
const ticketLogin = async (ticket: string, setUser: React.Dispatch>) => {
- let url = '/api/login?ticket=' + ticket
- if (DEBUG) {
- url = 'http://127.0.0.1:8000/api/login?ticket=' + ticket
- }
- const token = await (await fetch(url, {method: 'POST', headers: {'Content-Type': 'application/json'}}))
- .json() as Token
+ const token: Token = await post_ticket(ticket)
if (token.token) {
localStorage.setItem('token', token.token)
const result: loginLoaderObject = await loginLoader()
- if (result.user) {
+ if (isUser(result.user)) {
setUser(result.user)
}else{
localStorage.removeItem('token')
@@ -34,6 +29,10 @@ const ticketLogin = async (ticket: string, setUser: React.Dispatch {
+ return (data && data.user_id && data.user_name && data.user_email && data.user_roles);
+}
+
export default function LoginScreen(): JSX.Element {
const {user, setUser} = useAuth();
const location = useLocation() as location_type;
@@ -52,9 +51,13 @@ export default function LoginScreen(): JSX.Element {
useEffect(() => {
// If the saved token is valid => the user will be logged in
if (data && data.user) {
- setUser(data.user)
- }
- else if (!user && ticket) {
+ if (isUser(data.user)) {
+ setUser(data.user)
+ }else{
+ setUser(undefined)
+ localStorage.removeItem('token')
+ }
+ } else if (!user && ticket) {
void ticketLogin(ticket, setUser);
}
}, [data, setUser, ticket, user]);
diff --git a/frontend/src/utils/api/ApiFetch.ts b/frontend/src/utils/ApiFetch.ts
similarity index 91%
rename from frontend/src/utils/api/ApiFetch.ts
rename to frontend/src/utils/ApiFetch.ts
index e4934a1d..19c8d250 100644
--- a/frontend/src/utils/api/ApiFetch.ts
+++ b/frontend/src/utils/ApiFetch.ts
@@ -1,4 +1,4 @@
-import {DEBUG} from "../../pages/root.tsx";
+import {DEBUG} from "../pages/root.tsx";
const ApiFetch = async (url: string, options?: RequestInit) => {
diff --git a/frontend/src/utils/InputInterfaces.ts b/frontend/src/utils/InputInterfaces.ts
new file mode 100644
index 00000000..a2514a70
--- /dev/null
+++ b/frontend/src/utils/InputInterfaces.ts
@@ -0,0 +1,9 @@
+export interface ProjectInput{
+ name: string,
+ deadline: Date,
+ archived: boolean,
+ description: string,
+ requirements: string,
+ visible: boolean,
+ max_students: number,
+}
\ No newline at end of file
diff --git a/frontend/src/utils/api/Groups.ts b/frontend/src/utils/api/Groups.ts
index 54bc3af5..2edec938 100644
--- a/frontend/src/utils/api/Groups.ts
+++ b/frontend/src/utils/api/Groups.ts
@@ -1,4 +1,4 @@
-import ApiFetch from "./ApiFetch.ts";
+import ApiFetch from "../ApiFetch.ts";
export function joinGroup(groupId: number) {
void ApiFetch(`/groups/${groupId}/join`,
@@ -8,16 +8,4 @@ export function joinGroup(groupId: number) {
export function leaveGroup(groupId: number) {
void ApiFetch(`/groups/${groupId}/leave`,
{method: 'POST', headers: {'Content-Type': 'application/json'}});
-}
-
-export async function listGroupMembers(groupId: number) {
- let members = await ApiFetch(`/groups/${groupId}/members`,
- {method: 'GET', headers: {'Content-Type': 'application/json'}});
- return members;
-}
-
-export function projectGroup(projectId: number) {
- let group = void ApiFetch(`/projects/${projectId}/group`,
- {method: 'GET', headers: {'Content-Type': 'application/json'}});
- return group;
}
\ No newline at end of file
diff --git a/frontend/src/utils/api/Login.ts b/frontend/src/utils/api/Login.ts
index e69de29b..af35a0f5 100644
--- a/frontend/src/utils/api/Login.ts
+++ b/frontend/src/utils/api/Login.ts
@@ -0,0 +1,16 @@
+import {DEBUG} from "../../pages/root.tsx";
+import {Token} from "../ApiInterfaces.ts";
+
+export async function post_ticket(ticket: string){
+ let url = '/api/login?ticket=' + ticket
+ if (DEBUG) {
+ url = 'http://127.0.0.1:8000/api/login?ticket=' + ticket
+ }
+
+ return await (await fetch(url, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json'
+ },}))
+ .json() as Token
+}
\ No newline at end of file
diff --git a/frontend/src/utils/api/Project.ts b/frontend/src/utils/api/Project.ts
index e69de29b..04e62b87 100644
--- a/frontend/src/utils/api/Project.ts
+++ b/frontend/src/utils/api/Project.ts
@@ -0,0 +1,36 @@
+import apiFetch from "../ApiFetch.ts";
+import {ProjectInput} from "../InputInterfaces.ts";
+import {Backend_group, Backend_Project} from "../BackendInterfaces.ts";
+import {mapGroup} from "../ApiTypesMapper.ts";
+
+export async function project_create_group(project_id: number){
+ const groupData = await apiFetch(`/projects/${project_id}/groups`, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json'
+ }
+ }) as Backend_group
+ return mapGroup(groupData)
+}
+
+export async function update_project(project_id: number, projectInput: ProjectInput){
+ const projectData = await apiFetch(`/projects/${project_id}`, {
+ method: 'PATCH',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify(projectInput)
+ }) as Backend_Project
+ return {
+ project_id: projectData.id,
+ project_name: projectData.name,
+ project_deadline: projectData.deadline,
+ project_archived: projectData.archived,
+ project_description: projectData.description,
+ project_requirements: projectData.requirements,
+ project_visible: projectData.visible,
+ project_max_students: projectData.max_students,
+ subject_id: projectData.subject_id
+ }
+}
+
diff --git a/frontend/src/utils/api/Student.ts b/frontend/src/utils/api/Student.ts
index e69de29b..2269b84b 100644
--- a/frontend/src/utils/api/Student.ts
+++ b/frontend/src/utils/api/Student.ts
@@ -0,0 +1,7 @@
+import apiFetch from "../ApiFetch.ts";
+
+export function join_subject(subjectId: number){
+ void apiFetch(`/student/subjects/${subjectId}/join`, {
+ method: 'POST'
+ })
+}
\ No newline at end of file
diff --git a/frontend/src/utils/api/Subject.ts b/frontend/src/utils/api/Subject.ts
index e69de29b..fa9850f3 100644
--- a/frontend/src/utils/api/Subject.ts
+++ b/frontend/src/utils/api/Subject.ts
@@ -0,0 +1,25 @@
+import {ProjectInput} from "../InputInterfaces.ts";
+import ApiFetch from "../ApiFetch.ts";
+import {Backend_Project} from "../BackendInterfaces.ts";
+
+export async function subject_create_project(subjectId: number, projectInput: ProjectInput) {
+ const projectData: Backend_Project = (await ApiFetch(`/subjects/${subjectId}/projects`, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify(projectInput)
+ }) as Backend_Project)
+
+ return {
+ project_id: projectData.id,
+ project_name: projectData.name,
+ project_deadline: projectData.deadline,
+ project_archived: projectData.archived,
+ project_description: projectData.description,
+ project_requirements: projectData.requirements,
+ project_visible: projectData.visible,
+ project_max_students: projectData.max_students,
+ subject_id: projectData.subject_id
+ }
+}
\ No newline at end of file
diff --git a/frontend/src/utils/api/Teacher.ts b/frontend/src/utils/api/Teacher.ts
index e69de29b..ab4a1a09 100644
--- a/frontend/src/utils/api/Teacher.ts
+++ b/frontend/src/utils/api/Teacher.ts
@@ -0,0 +1,13 @@
+import {Backend_Subject} from "../BackendInterfaces.ts";
+import apiFetch from "../ApiFetch.ts";
+
+export async function createSubject(name: string) {
+ return (await apiFetch('/teacher/subjects',
+ {
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ method: 'POST',
+ body: JSON.stringify({name: name})
+ })) as Backend_Subject
+}
\ No newline at end of file
diff --git a/frontend/src/utils/api/User.ts b/frontend/src/utils/api/User.ts
index e69de29b..f731bc77 100644
--- a/frontend/src/utils/api/User.ts
+++ b/frontend/src/utils/api/User.ts
@@ -0,0 +1,8 @@
+import {Language} from "../../components/Settings.tsx";
+import apiFetch from "../ApiFetch.ts";
+
+export function modify_language(language: Language){
+ void apiFetch(`/user?language=${language}`, {
+ method: 'PATCH'
+ })
+}
\ No newline at end of file
From 3f6508cce0ce659d54fa951829b3fe8b08c56a57 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stef=20Oss=C3=A9?=
Date: Tue, 9 Apr 2024 21:42:08 +0200
Subject: [PATCH 03/90] debug false
---
frontend/src/pages/root.tsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/frontend/src/pages/root.tsx b/frontend/src/pages/root.tsx
index 747c296a..a9c2d7b2 100644
--- a/frontend/src/pages/root.tsx
+++ b/frontend/src/pages/root.tsx
@@ -2,7 +2,7 @@ import {JSX} from "react";
import useAuth from "../hooks/useAuth.ts";
import {Navigate} from "react-router-dom";
-export const DEBUG: boolean = true; // should always be false on the repo.
+export const DEBUG: boolean = false; // should always be false on the repo.
export default function Root(): JSX.Element {
const {user} = useAuth()
From 135265f9bfeb70a917f6b82263ff35addf3fc375 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stef=20Oss=C3=A9?=
Date: Tue, 9 Apr 2024 22:07:49 +0200
Subject: [PATCH 04/90] Revert "Functies user, projects, subjects, group,
course"
This reverts commit 81deb20f15122f7619437595a133be383bd6c4dd.
---
.../components/authentication/ErrorLogin.tsx | 2 +-
.../{LoginLoader.tsx => LoginLoader.ts} | 2 +-
.../src/dataloaders/ProjectsStudentLoader.ts | 2 +-
frontend/src/dataloaders/SharedFunctions.ts | 2 +-
.../src/dataloaders/projectsTeacherLoader.ts | 2 +-
frontend/src/main.tsx | 6 ++--
frontend/src/pages/Test.tsx | 12 +++++++
frontend/src/pages/login/LoginScreen.tsx | 27 +++++++-------
frontend/src/utils/InputInterfaces.ts | 9 -----
frontend/src/utils/{ => api}/ApiFetch.ts | 2 +-
frontend/src/utils/api/Groups.ts | 14 +++++++-
frontend/src/utils/api/Login.ts | 16 ---------
frontend/src/utils/api/Project.ts | 36 -------------------
frontend/src/utils/api/Student.ts | 7 ----
frontend/src/utils/api/Subject.ts | 25 -------------
frontend/src/utils/api/Teacher.ts | 13 -------
frontend/src/utils/api/User.ts | 8 -----
17 files changed, 46 insertions(+), 139 deletions(-)
rename frontend/src/dataloaders/{LoginLoader.tsx => LoginLoader.ts} (93%)
create mode 100644 frontend/src/pages/Test.tsx
delete mode 100644 frontend/src/utils/InputInterfaces.ts
rename frontend/src/utils/{ => api}/ApiFetch.ts (91%)
diff --git a/frontend/src/components/authentication/ErrorLogin.tsx b/frontend/src/components/authentication/ErrorLogin.tsx
index 1e0ab292..0ab4aa45 100644
--- a/frontend/src/components/authentication/ErrorLogin.tsx
+++ b/frontend/src/components/authentication/ErrorLogin.tsx
@@ -1,5 +1,5 @@
import {JSX} from "react";
-import delphi_full from "/delphi_full.png";
+import delphi_full from "../../../public/delphi_full.png";
export default function ErrorLogin(): JSX.Element {
diff --git a/frontend/src/dataloaders/LoginLoader.tsx b/frontend/src/dataloaders/LoginLoader.ts
similarity index 93%
rename from frontend/src/dataloaders/LoginLoader.tsx
rename to frontend/src/dataloaders/LoginLoader.ts
index 7c96b78e..9edadd53 100644
--- a/frontend/src/dataloaders/LoginLoader.tsx
+++ b/frontend/src/dataloaders/LoginLoader.ts
@@ -1,7 +1,7 @@
import {User} from "../utils/ApiInterfaces.ts";
import {Backend_user} from "../utils/BackendInterfaces.ts";
import {mapUser} from "../utils/ApiTypesMapper.ts";
-import apiFetch from "../utils/ApiFetch.ts";
+import apiFetch from "../utils/api/ApiFetch.ts";
export const LOGIN_ROUTER_ID = "login";
diff --git a/frontend/src/dataloaders/ProjectsStudentLoader.ts b/frontend/src/dataloaders/ProjectsStudentLoader.ts
index 9e782310..43b29101 100644
--- a/frontend/src/dataloaders/ProjectsStudentLoader.ts
+++ b/frontend/src/dataloaders/ProjectsStudentLoader.ts
@@ -1,6 +1,6 @@
import {CompleteProject, Group, Submission} from "../utils/ApiInterfaces.ts";
import {getAllProjectsAndSubjects, teacherStudentRole} from "./SharedFunctions.ts";
-import apiFetch from "../utils/ApiFetch.ts";
+import apiFetch from "../utils/api/ApiFetch.ts";
import {Backend_group, Backend_submission} from "../utils/BackendInterfaces.ts";
import {mapGroup, mapSubmission} from "../utils/ApiTypesMapper.ts";
diff --git a/frontend/src/dataloaders/SharedFunctions.ts b/frontend/src/dataloaders/SharedFunctions.ts
index da516496..89c9e2d1 100644
--- a/frontend/src/dataloaders/SharedFunctions.ts
+++ b/frontend/src/dataloaders/SharedFunctions.ts
@@ -1,7 +1,7 @@
import {Project, properSubject, Subject} from "../utils/ApiInterfaces.ts";
import {mapProjectList, mapSubjectList} from "../utils/ApiTypesMapper.ts";
import {Backend_Project, Backend_Subject} from "../utils/BackendInterfaces.ts";
-import apiFetch from "../utils/ApiFetch.ts";
+import apiFetch from "../utils/api/ApiFetch.ts";
export enum teacherStudentRole {
STUDENT = "student",
diff --git a/frontend/src/dataloaders/projectsTeacherLoader.ts b/frontend/src/dataloaders/projectsTeacherLoader.ts
index 87fedcea..a709ecf1 100644
--- a/frontend/src/dataloaders/projectsTeacherLoader.ts
+++ b/frontend/src/dataloaders/projectsTeacherLoader.ts
@@ -1,6 +1,6 @@
import {CompleteProjectTeacher, Group, Submission} from "../utils/ApiInterfaces.ts";
import {getAllProjectsAndSubjects, teacherStudentRole} from "./SharedFunctions.ts";
-import apiFetch from "../utils/ApiFetch.ts";
+import apiFetch from "../utils/api/ApiFetch.ts";
import {Backend_group} from "../utils/BackendInterfaces.ts";
import {mapGroupList} from "../utils/ApiTypesMapper.ts";
diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx
index 2014e4b9..982d6dfb 100644
--- a/frontend/src/main.tsx
+++ b/frontend/src/main.tsx
@@ -12,7 +12,7 @@ import studentLoader, {STUDENT_ROUTER_ID} from "./dataloaders/StudentLoader.ts";
import Unauthorized from "./components/authentication/Unauthorized.tsx";
import teacherLoader, {TEACHER_ROUTER_ID} from "./dataloaders/TeacherLoader.ts";
// import coursesTeacherLoader, {SUBJECT_TEACHER_ROUTER_ID} from "./dataloaders/CoursesTeacherLoader.ts";
-import loginLoader, {LOGIN_ROUTER_ID} from "./dataloaders/LoginLoader.tsx";
+import loginLoader, {LOGIN_ROUTER_ID} from "./dataloaders/LoginLoader.ts";
import ErrorLogin from "./components/authentication/ErrorLogin.tsx";
import ProjectsViewStudent from "./pages/student/ProjectsViewStudent.tsx";
import CoursesViewStudent from "./pages/student/CoursesViewStudent.tsx";
@@ -46,7 +46,7 @@ const router = createBrowserRouter(
}/>
- }>
+ }>
} loader={studentLoader}/>
}
loader={projectsStudentLoader}/>
@@ -54,7 +54,7 @@ const router = createBrowserRouter(
loader={coursesStudentLoader}/>
- }>
+ }>
} loader={teacherLoader}/>
}
loader={projectsTeacherLoader}/>
diff --git a/frontend/src/pages/Test.tsx b/frontend/src/pages/Test.tsx
new file mode 100644
index 00000000..626d973e
--- /dev/null
+++ b/frontend/src/pages/Test.tsx
@@ -0,0 +1,12 @@
+import {projectGroup} from "../utils/api/Groups.ts";
+
+export default function Test () {
+ function clickEvent () {
+ console.log(projectGroup(2))
+ }
+
+ return (
+
Welcome on this test page, click the button below to test te function
+
+ )
+}
\ No newline at end of file
diff --git a/frontend/src/pages/login/LoginScreen.tsx b/frontend/src/pages/login/LoginScreen.tsx
index f02eea18..7b9ec838 100644
--- a/frontend/src/pages/login/LoginScreen.tsx
+++ b/frontend/src/pages/login/LoginScreen.tsx
@@ -1,10 +1,10 @@
import React, {JSX, useEffect} from "react";
import {Navigate, useLocation, useRouteLoaderData} from 'react-router-dom';
import useAuth from "../../hooks/useAuth.ts";
-import loginLoader, {LOGIN_ROUTER_ID, loginLoaderObject} from "../../dataloaders/LoginLoader.tsx";
+import loginLoader, {LOGIN_ROUTER_ID, loginLoaderObject} from "../../dataloaders/LoginLoader.ts";
import LoginForm from "../../components/authentication/LoginForm.tsx";
+import {DEBUG} from "../root.tsx";
import {Token, User} from "../../utils/ApiInterfaces.ts";
-import {post_ticket} from "../../utils/api/Login.ts";
interface location_type {
search?: { ticket?: string },
@@ -13,12 +13,17 @@ interface location_type {
}
const ticketLogin = async (ticket: string, setUser: React.Dispatch>) => {
- const token: Token = await post_ticket(ticket)
+ let url = '/api/login?ticket=' + ticket
+ if (DEBUG) {
+ url = 'http://127.0.0.1:8000/api/login?ticket=' + ticket
+ }
+ const token = await (await fetch(url, {method: 'POST', headers: {'Content-Type': 'application/json'}}))
+ .json() as Token
if (token.token) {
localStorage.setItem('token', token.token)
const result: loginLoaderObject = await loginLoader()
- if (isUser(result.user)) {
+ if (result.user) {
setUser(result.user)
}else{
localStorage.removeItem('token')
@@ -29,10 +34,6 @@ const ticketLogin = async (ticket: string, setUser: React.Dispatch {
- return (data && data.user_id && data.user_name && data.user_email && data.user_roles);
-}
-
export default function LoginScreen(): JSX.Element {
const {user, setUser} = useAuth();
const location = useLocation() as location_type;
@@ -51,13 +52,9 @@ export default function LoginScreen(): JSX.Element {
useEffect(() => {
// If the saved token is valid => the user will be logged in
if (data && data.user) {
- if (isUser(data.user)) {
- setUser(data.user)
- }else{
- setUser(undefined)
- localStorage.removeItem('token')
- }
- } else if (!user && ticket) {
+ setUser(data.user)
+ }
+ else if (!user && ticket) {
void ticketLogin(ticket, setUser);
}
}, [data, setUser, ticket, user]);
diff --git a/frontend/src/utils/InputInterfaces.ts b/frontend/src/utils/InputInterfaces.ts
deleted file mode 100644
index a2514a70..00000000
--- a/frontend/src/utils/InputInterfaces.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-export interface ProjectInput{
- name: string,
- deadline: Date,
- archived: boolean,
- description: string,
- requirements: string,
- visible: boolean,
- max_students: number,
-}
\ No newline at end of file
diff --git a/frontend/src/utils/ApiFetch.ts b/frontend/src/utils/api/ApiFetch.ts
similarity index 91%
rename from frontend/src/utils/ApiFetch.ts
rename to frontend/src/utils/api/ApiFetch.ts
index 19c8d250..e4934a1d 100644
--- a/frontend/src/utils/ApiFetch.ts
+++ b/frontend/src/utils/api/ApiFetch.ts
@@ -1,4 +1,4 @@
-import {DEBUG} from "../pages/root.tsx";
+import {DEBUG} from "../../pages/root.tsx";
const ApiFetch = async (url: string, options?: RequestInit) => {
diff --git a/frontend/src/utils/api/Groups.ts b/frontend/src/utils/api/Groups.ts
index 2edec938..54bc3af5 100644
--- a/frontend/src/utils/api/Groups.ts
+++ b/frontend/src/utils/api/Groups.ts
@@ -1,4 +1,4 @@
-import ApiFetch from "../ApiFetch.ts";
+import ApiFetch from "./ApiFetch.ts";
export function joinGroup(groupId: number) {
void ApiFetch(`/groups/${groupId}/join`,
@@ -8,4 +8,16 @@ export function joinGroup(groupId: number) {
export function leaveGroup(groupId: number) {
void ApiFetch(`/groups/${groupId}/leave`,
{method: 'POST', headers: {'Content-Type': 'application/json'}});
+}
+
+export async function listGroupMembers(groupId: number) {
+ let members = await ApiFetch(`/groups/${groupId}/members`,
+ {method: 'GET', headers: {'Content-Type': 'application/json'}});
+ return members;
+}
+
+export function projectGroup(projectId: number) {
+ let group = void ApiFetch(`/projects/${projectId}/group`,
+ {method: 'GET', headers: {'Content-Type': 'application/json'}});
+ return group;
}
\ No newline at end of file
diff --git a/frontend/src/utils/api/Login.ts b/frontend/src/utils/api/Login.ts
index af35a0f5..e69de29b 100644
--- a/frontend/src/utils/api/Login.ts
+++ b/frontend/src/utils/api/Login.ts
@@ -1,16 +0,0 @@
-import {DEBUG} from "../../pages/root.tsx";
-import {Token} from "../ApiInterfaces.ts";
-
-export async function post_ticket(ticket: string){
- let url = '/api/login?ticket=' + ticket
- if (DEBUG) {
- url = 'http://127.0.0.1:8000/api/login?ticket=' + ticket
- }
-
- return await (await fetch(url, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json'
- },}))
- .json() as Token
-}
\ No newline at end of file
diff --git a/frontend/src/utils/api/Project.ts b/frontend/src/utils/api/Project.ts
index 04e62b87..e69de29b 100644
--- a/frontend/src/utils/api/Project.ts
+++ b/frontend/src/utils/api/Project.ts
@@ -1,36 +0,0 @@
-import apiFetch from "../ApiFetch.ts";
-import {ProjectInput} from "../InputInterfaces.ts";
-import {Backend_group, Backend_Project} from "../BackendInterfaces.ts";
-import {mapGroup} from "../ApiTypesMapper.ts";
-
-export async function project_create_group(project_id: number){
- const groupData = await apiFetch(`/projects/${project_id}/groups`, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json'
- }
- }) as Backend_group
- return mapGroup(groupData)
-}
-
-export async function update_project(project_id: number, projectInput: ProjectInput){
- const projectData = await apiFetch(`/projects/${project_id}`, {
- method: 'PATCH',
- headers: {
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify(projectInput)
- }) as Backend_Project
- return {
- project_id: projectData.id,
- project_name: projectData.name,
- project_deadline: projectData.deadline,
- project_archived: projectData.archived,
- project_description: projectData.description,
- project_requirements: projectData.requirements,
- project_visible: projectData.visible,
- project_max_students: projectData.max_students,
- subject_id: projectData.subject_id
- }
-}
-
diff --git a/frontend/src/utils/api/Student.ts b/frontend/src/utils/api/Student.ts
index 2269b84b..e69de29b 100644
--- a/frontend/src/utils/api/Student.ts
+++ b/frontend/src/utils/api/Student.ts
@@ -1,7 +0,0 @@
-import apiFetch from "../ApiFetch.ts";
-
-export function join_subject(subjectId: number){
- void apiFetch(`/student/subjects/${subjectId}/join`, {
- method: 'POST'
- })
-}
\ No newline at end of file
diff --git a/frontend/src/utils/api/Subject.ts b/frontend/src/utils/api/Subject.ts
index fa9850f3..e69de29b 100644
--- a/frontend/src/utils/api/Subject.ts
+++ b/frontend/src/utils/api/Subject.ts
@@ -1,25 +0,0 @@
-import {ProjectInput} from "../InputInterfaces.ts";
-import ApiFetch from "../ApiFetch.ts";
-import {Backend_Project} from "../BackendInterfaces.ts";
-
-export async function subject_create_project(subjectId: number, projectInput: ProjectInput) {
- const projectData: Backend_Project = (await ApiFetch(`/subjects/${subjectId}/projects`, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify(projectInput)
- }) as Backend_Project)
-
- return {
- project_id: projectData.id,
- project_name: projectData.name,
- project_deadline: projectData.deadline,
- project_archived: projectData.archived,
- project_description: projectData.description,
- project_requirements: projectData.requirements,
- project_visible: projectData.visible,
- project_max_students: projectData.max_students,
- subject_id: projectData.subject_id
- }
-}
\ No newline at end of file
diff --git a/frontend/src/utils/api/Teacher.ts b/frontend/src/utils/api/Teacher.ts
index ab4a1a09..e69de29b 100644
--- a/frontend/src/utils/api/Teacher.ts
+++ b/frontend/src/utils/api/Teacher.ts
@@ -1,13 +0,0 @@
-import {Backend_Subject} from "../BackendInterfaces.ts";
-import apiFetch from "../ApiFetch.ts";
-
-export async function createSubject(name: string) {
- return (await apiFetch('/teacher/subjects',
- {
- headers: {
- 'Content-Type': 'application/json'
- },
- method: 'POST',
- body: JSON.stringify({name: name})
- })) as Backend_Subject
-}
\ No newline at end of file
diff --git a/frontend/src/utils/api/User.ts b/frontend/src/utils/api/User.ts
index f731bc77..e69de29b 100644
--- a/frontend/src/utils/api/User.ts
+++ b/frontend/src/utils/api/User.ts
@@ -1,8 +0,0 @@
-import {Language} from "../../components/Settings.tsx";
-import apiFetch from "../ApiFetch.ts";
-
-export function modify_language(language: Language){
- void apiFetch(`/user?language=${language}`, {
- method: 'PATCH'
- })
-}
\ No newline at end of file
From 6669ee69b0f7c3493d0b5b117eb7b016237f1eb5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stef=20Oss=C3=A9?=
Date: Tue, 9 Apr 2024 21:39:56 +0200
Subject: [PATCH 05/90] Functies user, projects, subjects, group, course
---
.../components/authentication/ErrorLogin.tsx | 2 +-
.../{LoginLoader.ts => LoginLoader.tsx} | 2 +-
.../src/dataloaders/ProjectsStudentLoader.ts | 2 +-
frontend/src/dataloaders/SharedFunctions.ts | 2 +-
.../src/dataloaders/projectsTeacherLoader.ts | 2 +-
frontend/src/main.tsx | 6 ++--
frontend/src/pages/Test.tsx | 12 -------
frontend/src/pages/login/LoginScreen.tsx | 27 +++++++-------
frontend/src/utils/{api => }/ApiFetch.ts | 2 +-
frontend/src/utils/InputInterfaces.ts | 9 +++++
frontend/src/utils/api/Groups.ts | 14 +-------
frontend/src/utils/api/Login.ts | 16 +++++++++
frontend/src/utils/api/Project.ts | 36 +++++++++++++++++++
frontend/src/utils/api/Student.ts | 7 ++++
frontend/src/utils/api/Subject.ts | 25 +++++++++++++
frontend/src/utils/api/Teacher.ts | 13 +++++++
frontend/src/utils/api/User.ts | 8 +++++
17 files changed, 139 insertions(+), 46 deletions(-)
rename frontend/src/dataloaders/{LoginLoader.ts => LoginLoader.tsx} (93%)
delete mode 100644 frontend/src/pages/Test.tsx
rename frontend/src/utils/{api => }/ApiFetch.ts (91%)
create mode 100644 frontend/src/utils/InputInterfaces.ts
diff --git a/frontend/src/components/authentication/ErrorLogin.tsx b/frontend/src/components/authentication/ErrorLogin.tsx
index 0ab4aa45..1e0ab292 100644
--- a/frontend/src/components/authentication/ErrorLogin.tsx
+++ b/frontend/src/components/authentication/ErrorLogin.tsx
@@ -1,5 +1,5 @@
import {JSX} from "react";
-import delphi_full from "../../../public/delphi_full.png";
+import delphi_full from "/delphi_full.png";
export default function ErrorLogin(): JSX.Element {
diff --git a/frontend/src/dataloaders/LoginLoader.ts b/frontend/src/dataloaders/LoginLoader.tsx
similarity index 93%
rename from frontend/src/dataloaders/LoginLoader.ts
rename to frontend/src/dataloaders/LoginLoader.tsx
index 9edadd53..7c96b78e 100644
--- a/frontend/src/dataloaders/LoginLoader.ts
+++ b/frontend/src/dataloaders/LoginLoader.tsx
@@ -1,7 +1,7 @@
import {User} from "../utils/ApiInterfaces.ts";
import {Backend_user} from "../utils/BackendInterfaces.ts";
import {mapUser} from "../utils/ApiTypesMapper.ts";
-import apiFetch from "../utils/api/ApiFetch.ts";
+import apiFetch from "../utils/ApiFetch.ts";
export const LOGIN_ROUTER_ID = "login";
diff --git a/frontend/src/dataloaders/ProjectsStudentLoader.ts b/frontend/src/dataloaders/ProjectsStudentLoader.ts
index 43b29101..9e782310 100644
--- a/frontend/src/dataloaders/ProjectsStudentLoader.ts
+++ b/frontend/src/dataloaders/ProjectsStudentLoader.ts
@@ -1,6 +1,6 @@
import {CompleteProject, Group, Submission} from "../utils/ApiInterfaces.ts";
import {getAllProjectsAndSubjects, teacherStudentRole} from "./SharedFunctions.ts";
-import apiFetch from "../utils/api/ApiFetch.ts";
+import apiFetch from "../utils/ApiFetch.ts";
import {Backend_group, Backend_submission} from "../utils/BackendInterfaces.ts";
import {mapGroup, mapSubmission} from "../utils/ApiTypesMapper.ts";
diff --git a/frontend/src/dataloaders/SharedFunctions.ts b/frontend/src/dataloaders/SharedFunctions.ts
index 89c9e2d1..da516496 100644
--- a/frontend/src/dataloaders/SharedFunctions.ts
+++ b/frontend/src/dataloaders/SharedFunctions.ts
@@ -1,7 +1,7 @@
import {Project, properSubject, Subject} from "../utils/ApiInterfaces.ts";
import {mapProjectList, mapSubjectList} from "../utils/ApiTypesMapper.ts";
import {Backend_Project, Backend_Subject} from "../utils/BackendInterfaces.ts";
-import apiFetch from "../utils/api/ApiFetch.ts";
+import apiFetch from "../utils/ApiFetch.ts";
export enum teacherStudentRole {
STUDENT = "student",
diff --git a/frontend/src/dataloaders/projectsTeacherLoader.ts b/frontend/src/dataloaders/projectsTeacherLoader.ts
index a709ecf1..87fedcea 100644
--- a/frontend/src/dataloaders/projectsTeacherLoader.ts
+++ b/frontend/src/dataloaders/projectsTeacherLoader.ts
@@ -1,6 +1,6 @@
import {CompleteProjectTeacher, Group, Submission} from "../utils/ApiInterfaces.ts";
import {getAllProjectsAndSubjects, teacherStudentRole} from "./SharedFunctions.ts";
-import apiFetch from "../utils/api/ApiFetch.ts";
+import apiFetch from "../utils/ApiFetch.ts";
import {Backend_group} from "../utils/BackendInterfaces.ts";
import {mapGroupList} from "../utils/ApiTypesMapper.ts";
diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx
index 982d6dfb..2014e4b9 100644
--- a/frontend/src/main.tsx
+++ b/frontend/src/main.tsx
@@ -12,7 +12,7 @@ import studentLoader, {STUDENT_ROUTER_ID} from "./dataloaders/StudentLoader.ts";
import Unauthorized from "./components/authentication/Unauthorized.tsx";
import teacherLoader, {TEACHER_ROUTER_ID} from "./dataloaders/TeacherLoader.ts";
// import coursesTeacherLoader, {SUBJECT_TEACHER_ROUTER_ID} from "./dataloaders/CoursesTeacherLoader.ts";
-import loginLoader, {LOGIN_ROUTER_ID} from "./dataloaders/LoginLoader.ts";
+import loginLoader, {LOGIN_ROUTER_ID} from "./dataloaders/LoginLoader.tsx";
import ErrorLogin from "./components/authentication/ErrorLogin.tsx";
import ProjectsViewStudent from "./pages/student/ProjectsViewStudent.tsx";
import CoursesViewStudent from "./pages/student/CoursesViewStudent.tsx";
@@ -46,7 +46,7 @@ const router = createBrowserRouter(
}/>
- }>
+ }>
} loader={studentLoader}/>
}
loader={projectsStudentLoader}/>
@@ -54,7 +54,7 @@ const router = createBrowserRouter(
loader={coursesStudentLoader}/>
- }>
+ }>
} loader={teacherLoader}/>
}
loader={projectsTeacherLoader}/>
diff --git a/frontend/src/pages/Test.tsx b/frontend/src/pages/Test.tsx
deleted file mode 100644
index 626d973e..00000000
--- a/frontend/src/pages/Test.tsx
+++ /dev/null
@@ -1,12 +0,0 @@
-import {projectGroup} from "../utils/api/Groups.ts";
-
-export default function Test () {
- function clickEvent () {
- console.log(projectGroup(2))
- }
-
- return (
-
Welcome on this test page, click the button below to test te function
-
- )
-}
\ No newline at end of file
diff --git a/frontend/src/pages/login/LoginScreen.tsx b/frontend/src/pages/login/LoginScreen.tsx
index 7b9ec838..f02eea18 100644
--- a/frontend/src/pages/login/LoginScreen.tsx
+++ b/frontend/src/pages/login/LoginScreen.tsx
@@ -1,10 +1,10 @@
import React, {JSX, useEffect} from "react";
import {Navigate, useLocation, useRouteLoaderData} from 'react-router-dom';
import useAuth from "../../hooks/useAuth.ts";
-import loginLoader, {LOGIN_ROUTER_ID, loginLoaderObject} from "../../dataloaders/LoginLoader.ts";
+import loginLoader, {LOGIN_ROUTER_ID, loginLoaderObject} from "../../dataloaders/LoginLoader.tsx";
import LoginForm from "../../components/authentication/LoginForm.tsx";
-import {DEBUG} from "../root.tsx";
import {Token, User} from "../../utils/ApiInterfaces.ts";
+import {post_ticket} from "../../utils/api/Login.ts";
interface location_type {
search?: { ticket?: string },
@@ -13,17 +13,12 @@ interface location_type {
}
const ticketLogin = async (ticket: string, setUser: React.Dispatch>) => {
- let url = '/api/login?ticket=' + ticket
- if (DEBUG) {
- url = 'http://127.0.0.1:8000/api/login?ticket=' + ticket
- }
- const token = await (await fetch(url, {method: 'POST', headers: {'Content-Type': 'application/json'}}))
- .json() as Token
+ const token: Token = await post_ticket(ticket)
if (token.token) {
localStorage.setItem('token', token.token)
const result: loginLoaderObject = await loginLoader()
- if (result.user) {
+ if (isUser(result.user)) {
setUser(result.user)
}else{
localStorage.removeItem('token')
@@ -34,6 +29,10 @@ const ticketLogin = async (ticket: string, setUser: React.Dispatch {
+ return (data && data.user_id && data.user_name && data.user_email && data.user_roles);
+}
+
export default function LoginScreen(): JSX.Element {
const {user, setUser} = useAuth();
const location = useLocation() as location_type;
@@ -52,9 +51,13 @@ export default function LoginScreen(): JSX.Element {
useEffect(() => {
// If the saved token is valid => the user will be logged in
if (data && data.user) {
- setUser(data.user)
- }
- else if (!user && ticket) {
+ if (isUser(data.user)) {
+ setUser(data.user)
+ }else{
+ setUser(undefined)
+ localStorage.removeItem('token')
+ }
+ } else if (!user && ticket) {
void ticketLogin(ticket, setUser);
}
}, [data, setUser, ticket, user]);
diff --git a/frontend/src/utils/api/ApiFetch.ts b/frontend/src/utils/ApiFetch.ts
similarity index 91%
rename from frontend/src/utils/api/ApiFetch.ts
rename to frontend/src/utils/ApiFetch.ts
index e4934a1d..19c8d250 100644
--- a/frontend/src/utils/api/ApiFetch.ts
+++ b/frontend/src/utils/ApiFetch.ts
@@ -1,4 +1,4 @@
-import {DEBUG} from "../../pages/root.tsx";
+import {DEBUG} from "../pages/root.tsx";
const ApiFetch = async (url: string, options?: RequestInit) => {
diff --git a/frontend/src/utils/InputInterfaces.ts b/frontend/src/utils/InputInterfaces.ts
new file mode 100644
index 00000000..a2514a70
--- /dev/null
+++ b/frontend/src/utils/InputInterfaces.ts
@@ -0,0 +1,9 @@
+export interface ProjectInput{
+ name: string,
+ deadline: Date,
+ archived: boolean,
+ description: string,
+ requirements: string,
+ visible: boolean,
+ max_students: number,
+}
\ No newline at end of file
diff --git a/frontend/src/utils/api/Groups.ts b/frontend/src/utils/api/Groups.ts
index 54bc3af5..2edec938 100644
--- a/frontend/src/utils/api/Groups.ts
+++ b/frontend/src/utils/api/Groups.ts
@@ -1,4 +1,4 @@
-import ApiFetch from "./ApiFetch.ts";
+import ApiFetch from "../ApiFetch.ts";
export function joinGroup(groupId: number) {
void ApiFetch(`/groups/${groupId}/join`,
@@ -8,16 +8,4 @@ export function joinGroup(groupId: number) {
export function leaveGroup(groupId: number) {
void ApiFetch(`/groups/${groupId}/leave`,
{method: 'POST', headers: {'Content-Type': 'application/json'}});
-}
-
-export async function listGroupMembers(groupId: number) {
- let members = await ApiFetch(`/groups/${groupId}/members`,
- {method: 'GET', headers: {'Content-Type': 'application/json'}});
- return members;
-}
-
-export function projectGroup(projectId: number) {
- let group = void ApiFetch(`/projects/${projectId}/group`,
- {method: 'GET', headers: {'Content-Type': 'application/json'}});
- return group;
}
\ No newline at end of file
diff --git a/frontend/src/utils/api/Login.ts b/frontend/src/utils/api/Login.ts
index e69de29b..af35a0f5 100644
--- a/frontend/src/utils/api/Login.ts
+++ b/frontend/src/utils/api/Login.ts
@@ -0,0 +1,16 @@
+import {DEBUG} from "../../pages/root.tsx";
+import {Token} from "../ApiInterfaces.ts";
+
+export async function post_ticket(ticket: string){
+ let url = '/api/login?ticket=' + ticket
+ if (DEBUG) {
+ url = 'http://127.0.0.1:8000/api/login?ticket=' + ticket
+ }
+
+ return await (await fetch(url, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json'
+ },}))
+ .json() as Token
+}
\ No newline at end of file
diff --git a/frontend/src/utils/api/Project.ts b/frontend/src/utils/api/Project.ts
index e69de29b..04e62b87 100644
--- a/frontend/src/utils/api/Project.ts
+++ b/frontend/src/utils/api/Project.ts
@@ -0,0 +1,36 @@
+import apiFetch from "../ApiFetch.ts";
+import {ProjectInput} from "../InputInterfaces.ts";
+import {Backend_group, Backend_Project} from "../BackendInterfaces.ts";
+import {mapGroup} from "../ApiTypesMapper.ts";
+
+export async function project_create_group(project_id: number){
+ const groupData = await apiFetch(`/projects/${project_id}/groups`, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json'
+ }
+ }) as Backend_group
+ return mapGroup(groupData)
+}
+
+export async function update_project(project_id: number, projectInput: ProjectInput){
+ const projectData = await apiFetch(`/projects/${project_id}`, {
+ method: 'PATCH',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify(projectInput)
+ }) as Backend_Project
+ return {
+ project_id: projectData.id,
+ project_name: projectData.name,
+ project_deadline: projectData.deadline,
+ project_archived: projectData.archived,
+ project_description: projectData.description,
+ project_requirements: projectData.requirements,
+ project_visible: projectData.visible,
+ project_max_students: projectData.max_students,
+ subject_id: projectData.subject_id
+ }
+}
+
diff --git a/frontend/src/utils/api/Student.ts b/frontend/src/utils/api/Student.ts
index e69de29b..2269b84b 100644
--- a/frontend/src/utils/api/Student.ts
+++ b/frontend/src/utils/api/Student.ts
@@ -0,0 +1,7 @@
+import apiFetch from "../ApiFetch.ts";
+
+export function join_subject(subjectId: number){
+ void apiFetch(`/student/subjects/${subjectId}/join`, {
+ method: 'POST'
+ })
+}
\ No newline at end of file
diff --git a/frontend/src/utils/api/Subject.ts b/frontend/src/utils/api/Subject.ts
index e69de29b..fa9850f3 100644
--- a/frontend/src/utils/api/Subject.ts
+++ b/frontend/src/utils/api/Subject.ts
@@ -0,0 +1,25 @@
+import {ProjectInput} from "../InputInterfaces.ts";
+import ApiFetch from "../ApiFetch.ts";
+import {Backend_Project} from "../BackendInterfaces.ts";
+
+export async function subject_create_project(subjectId: number, projectInput: ProjectInput) {
+ const projectData: Backend_Project = (await ApiFetch(`/subjects/${subjectId}/projects`, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify(projectInput)
+ }) as Backend_Project)
+
+ return {
+ project_id: projectData.id,
+ project_name: projectData.name,
+ project_deadline: projectData.deadline,
+ project_archived: projectData.archived,
+ project_description: projectData.description,
+ project_requirements: projectData.requirements,
+ project_visible: projectData.visible,
+ project_max_students: projectData.max_students,
+ subject_id: projectData.subject_id
+ }
+}
\ No newline at end of file
diff --git a/frontend/src/utils/api/Teacher.ts b/frontend/src/utils/api/Teacher.ts
index e69de29b..ab4a1a09 100644
--- a/frontend/src/utils/api/Teacher.ts
+++ b/frontend/src/utils/api/Teacher.ts
@@ -0,0 +1,13 @@
+import {Backend_Subject} from "../BackendInterfaces.ts";
+import apiFetch from "../ApiFetch.ts";
+
+export async function createSubject(name: string) {
+ return (await apiFetch('/teacher/subjects',
+ {
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ method: 'POST',
+ body: JSON.stringify({name: name})
+ })) as Backend_Subject
+}
\ No newline at end of file
diff --git a/frontend/src/utils/api/User.ts b/frontend/src/utils/api/User.ts
index e69de29b..f731bc77 100644
--- a/frontend/src/utils/api/User.ts
+++ b/frontend/src/utils/api/User.ts
@@ -0,0 +1,8 @@
+import {Language} from "../../components/Settings.tsx";
+import apiFetch from "../ApiFetch.ts";
+
+export function modify_language(language: Language){
+ void apiFetch(`/user?language=${language}`, {
+ method: 'PATCH'
+ })
+}
\ No newline at end of file
From 0e0f35b200bb079b2544b0ec5545d58c1149f506 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stef=20Oss=C3=A9?=
Date: Tue, 9 Apr 2024 22:28:48 +0200
Subject: [PATCH 06/90] debug false
---
frontend/src/pages/root.tsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/frontend/src/pages/root.tsx b/frontend/src/pages/root.tsx
index 747c296a..a9c2d7b2 100644
--- a/frontend/src/pages/root.tsx
+++ b/frontend/src/pages/root.tsx
@@ -2,7 +2,7 @@ import {JSX} from "react";
import useAuth from "../hooks/useAuth.ts";
import {Navigate} from "react-router-dom";
-export const DEBUG: boolean = true; // should always be false on the repo.
+export const DEBUG: boolean = false; // should always be false on the repo.
export default function Root(): JSX.Element {
const {user} = useAuth()
From 6341a6067b1a29c9b2987969bbd2f53569132c4b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stef=20Oss=C3=A9?=
Date: Tue, 9 Apr 2024 22:29:02 +0200
Subject: [PATCH 07/90] debug false
---
backend/app.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/backend/app.py b/backend/app.py
index 78f1ed44..a1eb9cb9 100644
--- a/backend/app.py
+++ b/backend/app.py
@@ -49,7 +49,7 @@
# Add Middlewares
app.add_middleware(DatabaseSessionMiddleware)
-DEBUG = True # Should always be false in repo
+DEBUG = False # Should always be false in repo
if DEBUG:
from fastapi.middleware.cors import CORSMiddleware
From 91776e9785606456d0a371c5ef72f3d617e7b781 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stef=20Oss=C3=A9?=
Date: Sat, 13 Apr 2024 09:15:40 +0200
Subject: [PATCH 08/90] small fix
---
.../{LoginLoader.tsx => LoginLoader.ts} | 0
frontend/src/main.tsx | 18 +++++++++---------
frontend/src/pages/login/LoginScreen.tsx | 2 +-
3 files changed, 10 insertions(+), 10 deletions(-)
rename frontend/src/dataloaders/{LoginLoader.tsx => LoginLoader.ts} (100%)
diff --git a/frontend/src/dataloaders/LoginLoader.tsx b/frontend/src/dataloaders/LoginLoader.ts
similarity index 100%
rename from frontend/src/dataloaders/LoginLoader.tsx
rename to frontend/src/dataloaders/LoginLoader.ts
diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx
index 2014e4b9..5cdac8dd 100644
--- a/frontend/src/main.tsx
+++ b/frontend/src/main.tsx
@@ -12,7 +12,7 @@ import studentLoader, {STUDENT_ROUTER_ID} from "./dataloaders/StudentLoader.ts";
import Unauthorized from "./components/authentication/Unauthorized.tsx";
import teacherLoader, {TEACHER_ROUTER_ID} from "./dataloaders/TeacherLoader.ts";
// import coursesTeacherLoader, {SUBJECT_TEACHER_ROUTER_ID} from "./dataloaders/CoursesTeacherLoader.ts";
-import loginLoader, {LOGIN_ROUTER_ID} from "./dataloaders/LoginLoader.tsx";
+import loginLoader, {LOGIN_ROUTER_ID} from "./dataloaders/LoginLoader.ts";
import ErrorLogin from "./components/authentication/ErrorLogin.tsx";
import ProjectsViewStudent from "./pages/student/ProjectsViewStudent.tsx";
import CoursesViewStudent from "./pages/student/CoursesViewStudent.tsx";
@@ -46,20 +46,20 @@ const router = createBrowserRouter(
}/>
- }>
- } loader={studentLoader}/>
- }
+ }>
+ } loader={studentLoader}/>
+ }
loader={projectsStudentLoader}/>
- }
+ }
loader={coursesStudentLoader}/>
}>
- } loader={teacherLoader}/>
- }
+ } loader={teacherLoader}/>
+ }
loader={projectsTeacherLoader}/>
- }/>
- }/>
+ } loader={coursesTeacherLoader}/>
}/>
diff --git a/frontend/src/pages/login/LoginScreen.tsx b/frontend/src/pages/login/LoginScreen.tsx
index f02eea18..9e12869a 100644
--- a/frontend/src/pages/login/LoginScreen.tsx
+++ b/frontend/src/pages/login/LoginScreen.tsx
@@ -1,7 +1,7 @@
import React, {JSX, useEffect} from "react";
import {Navigate, useLocation, useRouteLoaderData} from 'react-router-dom';
import useAuth from "../../hooks/useAuth.ts";
-import loginLoader, {LOGIN_ROUTER_ID, loginLoaderObject} from "../../dataloaders/LoginLoader.tsx";
+import loginLoader, {LOGIN_ROUTER_ID, loginLoaderObject} from "../../dataloaders/LoginLoader.ts";
import LoginForm from "../../components/authentication/LoginForm.tsx";
import {Token, User} from "../../utils/ApiInterfaces.ts";
import {post_ticket} from "../../utils/api/Login.ts";
From 561bfea4ac94c3d3235753b6e4b5ee709b329056 Mon Sep 17 00:00:00 2001
From: Matthias Seghers
Date: Thu, 4 Apr 2024 15:25:14 +0200
Subject: [PATCH 09/90] little changes
---
frontend/src/dataloaders/SharedFunctions.ts | 6 ++----
frontend/src/utils/ApiInterfaces.ts | 2 +-
2 files changed, 3 insertions(+), 5 deletions(-)
diff --git a/frontend/src/dataloaders/SharedFunctions.ts b/frontend/src/dataloaders/SharedFunctions.ts
index 312f9913..8cabcdf1 100644
--- a/frontend/src/dataloaders/SharedFunctions.ts
+++ b/frontend/src/dataloaders/SharedFunctions.ts
@@ -7,10 +7,8 @@ export enum teacherStudentRole {
}
export async function projectsLoader(role: teacherStudentRole): Promise {
- const getter = await getAllProjectsAndSubjects(role);
- const subjects = getter.subjects;
- const projects = getter.projects;
- // TODO: add submission data
+ const {subjects, projects} = await getAllProjectsAndSubjects(role);
+ // TODO: add submission data there seems to no api available just yet.
for (let i = 0; i < projects.length; i++) {
const subject: Subject | undefined = subjects.find(subject => subject.id === projects[i].subject_id);
if (subject !== undefined) {
diff --git a/frontend/src/utils/ApiInterfaces.ts b/frontend/src/utils/ApiInterfaces.ts
index 6efe8f93..c7a721be 100644
--- a/frontend/src/utils/ApiInterfaces.ts
+++ b/frontend/src/utils/ApiInterfaces.ts
@@ -13,7 +13,7 @@ export interface Project {
visible: string,
max_students: number,
subject_id: number,
- subject_name: string | undefined | null
+ subject_name?: string
}
export interface properSubject {
From 0eafed3dca25d4ad7a203413d7a7547f33facc7f Mon Sep 17 00:00:00 2001
From: Matthias Seghers
Date: Thu, 4 Apr 2024 20:09:32 +0200
Subject: [PATCH 10/90] changed interface structure to better match api
---
frontend/src/dataloaders/SharedFunctions.ts | 28 +++++++---
frontend/src/utils/ApiInterfaces.ts | 58 ++++++++++++++-------
2 files changed, 59 insertions(+), 27 deletions(-)
diff --git a/frontend/src/dataloaders/SharedFunctions.ts b/frontend/src/dataloaders/SharedFunctions.ts
index 8cabcdf1..bd042e4e 100644
--- a/frontend/src/dataloaders/SharedFunctions.ts
+++ b/frontend/src/dataloaders/SharedFunctions.ts
@@ -1,4 +1,4 @@
-import {Project, Subject} from "../utils/ApiInterfaces.ts";
+import {CompleteProject, Group, Project, Subject, Submission} from "../utils/ApiInterfaces.ts";
import apiFetch from "../utils/ApiFetch.ts";
export enum teacherStudentRole {
@@ -6,16 +6,23 @@ export enum teacherStudentRole {
TEACHER = "teacher"
}
-export async function projectsLoader(role: teacherStudentRole): Promise {
+export async function projectsLoader(role: teacherStudentRole): Promise {
const {subjects, projects} = await getAllProjectsAndSubjects(role);
// TODO: add submission data there seems to no api available just yet.
- for (let i = 0; i < projects.length; i++) {
- const subject: Subject | undefined = subjects.find(subject => subject.id === projects[i].subject_id);
- if (subject !== undefined) {
- projects[i].subject_name = subject.name;
+ const submissions: Submission[] = await Promise.all(projects.map(project => {
+ return getSubmissionforProject(project.project_id);
+ }));
+ return projects.map((project, index) => {
+ const subject = subjects.find(subject => subject.subject_id === project.subject_id);
+ if (subject === undefined) {
+ throw Error("there should always be a subject for a project");
}
- }
- return projects;
+ return {
+ ...project,
+ ...subject,
+ ...submissions[index]
+ }
+ });
}
export interface projectsAndSubjects {
@@ -28,3 +35,8 @@ export async function getAllProjectsAndSubjects(role: teacherStudentRole): Promi
const subjects: Subject[] = (await apiFetch(`/${role}/subjects`)) as Subject[];
return {projects, subjects}
}
+
+export async function getSubmissionforProject(project_id: number): Promise {
+ const group: Group = (await apiFetch(`/projects/${project_id}/group`)) as Group;
+ return (await apiFetch(`/groups/${group.group_id}/submission`)) as Submission;
+}
diff --git a/frontend/src/utils/ApiInterfaces.ts b/frontend/src/utils/ApiInterfaces.ts
index c7a721be..ff17b611 100644
--- a/frontend/src/utils/ApiInterfaces.ts
+++ b/frontend/src/utils/ApiInterfaces.ts
@@ -1,24 +1,44 @@
export interface Subject {
- id: number,
- name: string
+ subject_id: number,
+ subject_name: string
}
export interface Project {
- id: number,
- name: string,
- deadline: string | Date,
- archived: boolean,
- description: string,
- requirements: string,
- visible: string,
- max_students: number,
- subject_id: number,
- subject_name?: string
+ project_id: number,
+ project_name: string,
+ project_deadline: string | Date,
+ project_archived: boolean,
+ project_description: string,
+ project_requirements: string,
+ project_visible: string,
+ project_max_students: number,
+ subject_id: number
}
-export interface properSubject {
- id: number,
- name: string,
+export enum SUBMISSION_STATE {
+ Pending = 1,
+ Approved = 2,
+ Rejected = 3
+}
+
+export interface Submission {
+ submission_id: number,
+ submission_date: string | Date,
+ submission_group_id: number,
+ submission_student_id: number,
+ submission_state: SUBMISSION_STATE,
+ submission_message: string,
+ submission_filename: string
+}
+
+export interface Group {
+ group_id: number,
+ project_id: number
+}
+
+export interface CompleteProject extends Project, Submission, Subject {}
+
+export interface properSubject extends Subject {
active_projects: number,
first_deadline: Date | null | string
}
@@ -28,8 +48,8 @@ export interface Token {
}
export interface User {
- id: number,
- name: string,
- email: string,
- roles: string[]
+ user_id: number,
+ user_name: string,
+ user_email: string,
+ user_roles: string[]
}
\ No newline at end of file
From d0efd58c098f61cdc6eeaf45de887f06cdca742b Mon Sep 17 00:00:00 2001
From: Matthias Seghers
Date: Fri, 5 Apr 2024 12:01:37 +0200
Subject: [PATCH 11/90] /teacher and /teacher/projects now have good loaders.
---
frontend/src/dataloaders/SharedFunctions.ts | 8 +++++---
frontend/src/dataloaders/StudentLoader.ts | 9 ++++-----
frontend/src/dataloaders/TeacherLoader.ts | 9 +++++----
frontend/src/dataloaders/projectsTeacherLoader.ts | 13 +++++++++++++
frontend/src/main.tsx | 3 ++-
5 files changed, 29 insertions(+), 13 deletions(-)
create mode 100644 frontend/src/dataloaders/projectsTeacherLoader.ts
diff --git a/frontend/src/dataloaders/SharedFunctions.ts b/frontend/src/dataloaders/SharedFunctions.ts
index bd042e4e..252fbb1a 100644
--- a/frontend/src/dataloaders/SharedFunctions.ts
+++ b/frontend/src/dataloaders/SharedFunctions.ts
@@ -8,9 +8,11 @@ export enum teacherStudentRole {
export async function projectsLoader(role: teacherStudentRole): Promise {
const {subjects, projects} = await getAllProjectsAndSubjects(role);
- // TODO: add submission data there seems to no api available just yet.
+ if (! Array.isArray(projects) || ! Array.isArray(subjects)) {
+ throw Error("Problem loading projects or courses.");
+ }
const submissions: Submission[] = await Promise.all(projects.map(project => {
- return getSubmissionforProject(project.project_id);
+ return getSubmissionForProject(project.project_id);
}));
return projects.map((project, index) => {
const subject = subjects.find(subject => subject.subject_id === project.subject_id);
@@ -36,7 +38,7 @@ export async function getAllProjectsAndSubjects(role: teacherStudentRole): Promi
return {projects, subjects}
}
-export async function getSubmissionforProject(project_id: number): Promise {
+export async function getSubmissionForProject(project_id: number): Promise {
const group: Group = (await apiFetch(`/projects/${project_id}/group`)) as Group;
return (await apiFetch(`/groups/${group.group_id}/submission`)) as Submission;
}
diff --git a/frontend/src/dataloaders/StudentLoader.ts b/frontend/src/dataloaders/StudentLoader.ts
index 39dd96d0..e8dc3eba 100644
--- a/frontend/src/dataloaders/StudentLoader.ts
+++ b/frontend/src/dataloaders/StudentLoader.ts
@@ -1,15 +1,14 @@
-import {Project} from "../utils/ApiInterfaces.ts";
+import {CompleteProject} from "../utils/ApiInterfaces.ts";
import {projectsLoader, teacherStudentRole} from "./SharedFunctions.ts";
export interface studentLoaderObject {
- projects: Project[]
+ projects: CompleteProject[]
}
export const STUDENT_ROUTER_ID = "student";
export default async function studentLoader(): Promise {
- const projects: Project[] = await projectsLoader(teacherStudentRole.STUDENT);
- // TODO: add submission data
- return {"projects": projects};
+ const projects: CompleteProject[] = await projectsLoader(teacherStudentRole.STUDENT);
+ return {projects};
}
\ No newline at end of file
diff --git a/frontend/src/dataloaders/TeacherLoader.ts b/frontend/src/dataloaders/TeacherLoader.ts
index da3e74ca..e2ea98e8 100644
--- a/frontend/src/dataloaders/TeacherLoader.ts
+++ b/frontend/src/dataloaders/TeacherLoader.ts
@@ -1,13 +1,14 @@
-import {Project} from "../utils/ApiInterfaces.ts";
+import {CompleteProject} from "../utils/ApiInterfaces.ts";
import {projectsLoader, teacherStudentRole} from "./SharedFunctions.ts";
export interface teacherLoaderObject {
- projects: Project[]
+ projects: CompleteProject[]
}
export const TEACHER_ROUTER_ID = "teacher";
export default async function teacherLoader(): Promise {
- const projects: Project[] = await projectsLoader(teacherStudentRole.TEACHER);
- return {"projects": projects}
+ const projects: CompleteProject[] = (await projectsLoader(teacherStudentRole.TEACHER))
+ .filter(project => !project.project_archived && project.project_visible);
+ return {projects};
}
\ No newline at end of file
diff --git a/frontend/src/dataloaders/projectsTeacherLoader.ts b/frontend/src/dataloaders/projectsTeacherLoader.ts
new file mode 100644
index 00000000..a330a59e
--- /dev/null
+++ b/frontend/src/dataloaders/projectsTeacherLoader.ts
@@ -0,0 +1,13 @@
+import {CompleteProject} from "../utils/ApiInterfaces.ts";
+import {projectsLoader, teacherStudentRole} from "./SharedFunctions.ts";
+
+export interface projectsTeacherLoaderObject {
+ projects: CompleteProject[]
+}
+
+export const PROJECTS_TEACHER_ROUTER_ID = "projects_teacher";
+
+export default async function projectsTeacherLoader(): Promise {
+ const projects: CompleteProject[] = await projectsLoader(teacherStudentRole.TEACHER);
+ return {projects};
+}
\ No newline at end of file
diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx
index f258a6f8..ca0f1260 100644
--- a/frontend/src/main.tsx
+++ b/frontend/src/main.tsx
@@ -24,6 +24,7 @@ import ProjectsViewTeacher from "./pages/teacher/ProjectsViewTeacher.tsx";
import CoursesViewTeacher from "./pages/teacher/CoursesViewTeacher.tsx";
import {CreateProject} from "./pages/teacher/CreateProject.tsx";
import CreateCourse from "./pages/teacher/CreateCourse.tsx";
+import projectsTeacherLoader, {PROJECTS_TEACHER_ROUTER_ID} from "./dataloaders/projectsTeacherLoader.ts";
const router = createBrowserRouter(
createRoutesFromElements(
@@ -50,7 +51,7 @@ const router = createBrowserRouter(
}>
} loader={teacherLoader}/>
- }/>
+ } loader={projectsTeacherLoader}/>
}/>
} /*loader={subjectsTeacherLoader} id={SUBJECT_TEACHER_ROUTER_ID}*//>
}/>
From de87852bfb215a837f702ab4b1a991b7620fac78 Mon Sep 17 00:00:00 2001
From: Matthias Seghers
Date: Fri, 5 Apr 2024 12:30:08 +0200
Subject: [PATCH 12/90] updated pre-commit to also check the linting of the
frontend
---
backend/.pre-commit-config.yaml | 7 +++-
.../src/dataloaders/SubjectsTeacherLoader.ts | 35 +++++++++----------
2 files changed, 23 insertions(+), 19 deletions(-)
diff --git a/backend/.pre-commit-config.yaml b/backend/.pre-commit-config.yaml
index fbd27e2b..9f74ecc4 100644
--- a/backend/.pre-commit-config.yaml
+++ b/backend/.pre-commit-config.yaml
@@ -12,4 +12,9 @@ repos:
entry: pyright
language: system
types: [python]
- always_run: true
\ No newline at end of file
+ always_run: true
+ - id: eslint-and-tsc
+ name: eslint and tsc linting checks
+ entry: pwd
+ language: system
+ always_run: true
diff --git a/frontend/src/dataloaders/SubjectsTeacherLoader.ts b/frontend/src/dataloaders/SubjectsTeacherLoader.ts
index e5c066a1..a6d08357 100644
--- a/frontend/src/dataloaders/SubjectsTeacherLoader.ts
+++ b/frontend/src/dataloaders/SubjectsTeacherLoader.ts
@@ -1,27 +1,26 @@
-import {Project, properSubject, Subject} from "../utils/ApiInterfaces.ts";
-import {getAllProjectsAndSubjects, projectsAndSubjects, teacherStudentRole} from "./SharedFunctions.ts";
+import {properSubject} from "../utils/ApiInterfaces.ts";
export interface subjectsTeacherLoaderObject {
subjects: properSubject[]
}
-export const SUBJECT_TEACHER_ROUTER_ID = "subjectTeacher";
+// export const SUBJECT_TEACHER_ROUTER_ID = "subjectTeacher";
export default async function subjectsTeacherLoader(): Promise {
- const temp: projectsAndSubjects = await getAllProjectsAndSubjects(teacherStudentRole.TEACHER);
- const subjects: Subject[] = temp.subjects;
- const projects: Project[] = temp.projects;
+ // const temp: projectsAndSubjects = await getAllProjectsAndSubjects(teacherStudentRole.TEACHER);
+ // const subjects: Subject[] = temp.subjects;
+ // const projects: Project[] = temp.projects;
- const p_subjects: properSubject[] = subjects.map(subject => {
- const active_projects = projects.filter(project =>
- project.archived && project.subject_id === subject.id
- );
- return {
- id: subject.id,
- name: subject.name,
- active_projects: active_projects.length,
- first_deadline: null // TODO: add deadlines when needed api endpoints are added.
- };
- });
- return {"subjects": p_subjects}
+ // const p_subjects: properSubject[] = subjects.map(subject => {
+ // const active_projects = projects.filter(project =>
+ // project.archived && project.subject_id === subject.id
+ // );
+ // return {
+ // id: subject.id,
+ // name: subject.name,
+ // active_projects: active_projects.length,
+ // first_deadline: null // TODO: add deadlines when needed api endpoints are added.
+ // };
+ // });
+ return {"subjects": []}
}
\ No newline at end of file
From 68b72e861f24710282a5a2d996cf191fdd083f67 Mon Sep 17 00:00:00 2001
From: Matthias Seghers
Date: Fri, 5 Apr 2024 12:45:39 +0200
Subject: [PATCH 13/90] updated pre-commit to also check the linting of the
frontend
---
backend/.pre-commit-config.yaml | 2 +-
frontend-lint-check.sh | 4 ++++
2 files changed, 5 insertions(+), 1 deletion(-)
create mode 100755 frontend-lint-check.sh
diff --git a/backend/.pre-commit-config.yaml b/backend/.pre-commit-config.yaml
index 9f74ecc4..38e73435 100644
--- a/backend/.pre-commit-config.yaml
+++ b/backend/.pre-commit-config.yaml
@@ -15,6 +15,6 @@ repos:
always_run: true
- id: eslint-and-tsc
name: eslint and tsc linting checks
- entry: pwd
+ entry: ./frontend-lint-check.sh
language: system
always_run: true
diff --git a/frontend-lint-check.sh b/frontend-lint-check.sh
new file mode 100755
index 00000000..95b9732f
--- /dev/null
+++ b/frontend-lint-check.sh
@@ -0,0 +1,4 @@
+#!/bin/bash
+
+cd frontend
+npm run lint
From 3ab12fa89b0a7958e3616fa2089f92263d1908e1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stef=20Oss=C3=A9?=
Date: Sat, 6 Apr 2024 16:39:26 +0200
Subject: [PATCH 14/90] fixing linting
---
frontend/src/components/Header.tsx | 2 +-
frontend/src/components/authentication/RequireAuth.tsx | 2 +-
frontend/src/pages/login/LoginScreen.tsx | 2 +-
frontend/src/pages/root.tsx | 6 +++---
4 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/frontend/src/components/Header.tsx b/frontend/src/components/Header.tsx
index f36e4380..eb041bf0 100644
--- a/frontend/src/components/Header.tsx
+++ b/frontend/src/components/Header.tsx
@@ -14,7 +14,7 @@ export function Header(props: { page_title: string, home: string }): JSX.Element
{props.page_title}
diff --git a/frontend/src/components/authentication/RequireAuth.tsx b/frontend/src/components/authentication/RequireAuth.tsx
index 3491ea11..7841130b 100644
--- a/frontend/src/components/authentication/RequireAuth.tsx
+++ b/frontend/src/components/authentication/RequireAuth.tsx
@@ -10,7 +10,7 @@ const RequireAuth = ({allowedRoles}: Props) => {
const location = useLocation();
if (user) {
return (
- (allowedRoles && user.roles.find(role => allowedRoles.includes(role)))
+ (allowedRoles && user.user_roles.find(role => allowedRoles.includes(role)))
?
:
);
diff --git a/frontend/src/pages/login/LoginScreen.tsx b/frontend/src/pages/login/LoginScreen.tsx
index 0f9beba1..e407a104 100644
--- a/frontend/src/pages/login/LoginScreen.tsx
+++ b/frontend/src/pages/login/LoginScreen.tsx
@@ -35,7 +35,7 @@ const ticketLogin = async (ticket: string, setUser: React.Dispatch {
- return (data && data.id && data.name && data.email && data.roles);
+ return (data && data.user_id && data.user_name && data.user_email && data.user_roles);
}
diff --git a/frontend/src/pages/root.tsx b/frontend/src/pages/root.tsx
index b87b4bb4..a9c2d7b2 100644
--- a/frontend/src/pages/root.tsx
+++ b/frontend/src/pages/root.tsx
@@ -8,11 +8,11 @@ export default function Root(): JSX.Element {
const {user} = useAuth()
let to: string = "/error"
- if (user?.roles.includes('TEACHER')) {
+ if (user?.user_roles.includes('TEACHER')) {
to = "/teacher";
- } else if (user?.roles.includes('STUDENT')) {
+ } else if (user?.user_roles.includes('STUDENT')) {
to = "/student";
- } else if (user?.roles.includes('ADMIN')) {
+ } else if (user?.user_roles.includes('ADMIN')) {
to = "/admin";
}
From c7ecf00954370ebe86ade5ed8d85cdaa7af34860 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stef=20Oss=C3=A9?=
Date: Tue, 9 Apr 2024 17:22:25 +0200
Subject: [PATCH 15/90] Created files
---
.../components/authentication/RequireAuth.tsx | 2 +-
frontend/src/dataloaders/LoginLoader.ts | 2 +-
frontend/src/dataloaders/SharedFunctions.ts | 2 +-
frontend/src/main.tsx | 2 ++
frontend/src/pages/Test.tsx | 12 ++++++++++
frontend/src/pages/login/LoginScreen.tsx | 2 +-
frontend/src/pages/root.tsx | 8 +++----
frontend/src/utils/ApiInterfaces.ts | 8 +++----
frontend/src/utils/{ => api}/ApiFetch.ts | 2 +-
frontend/src/utils/api/Groups.ts | 23 +++++++++++++++++++
frontend/src/utils/api/Login.ts | 0
frontend/src/utils/api/Project.ts | 0
frontend/src/utils/api/Student.ts | 0
frontend/src/utils/api/Subject.ts | 0
frontend/src/utils/api/Submission.ts | 0
frontend/src/utils/api/Teacher.ts | 0
frontend/src/utils/api/User.ts | 0
17 files changed, 50 insertions(+), 13 deletions(-)
create mode 100644 frontend/src/pages/Test.tsx
rename frontend/src/utils/{ => api}/ApiFetch.ts (91%)
create mode 100644 frontend/src/utils/api/Groups.ts
create mode 100644 frontend/src/utils/api/Login.ts
create mode 100644 frontend/src/utils/api/Project.ts
create mode 100644 frontend/src/utils/api/Student.ts
create mode 100644 frontend/src/utils/api/Subject.ts
create mode 100644 frontend/src/utils/api/Submission.ts
create mode 100644 frontend/src/utils/api/Teacher.ts
create mode 100644 frontend/src/utils/api/User.ts
diff --git a/frontend/src/components/authentication/RequireAuth.tsx b/frontend/src/components/authentication/RequireAuth.tsx
index 7841130b..3491ea11 100644
--- a/frontend/src/components/authentication/RequireAuth.tsx
+++ b/frontend/src/components/authentication/RequireAuth.tsx
@@ -10,7 +10,7 @@ const RequireAuth = ({allowedRoles}: Props) => {
const location = useLocation();
if (user) {
return (
- (allowedRoles && user.user_roles.find(role => allowedRoles.includes(role)))
+ (allowedRoles && user.roles.find(role => allowedRoles.includes(role)))
?
:
);
diff --git a/frontend/src/dataloaders/LoginLoader.ts b/frontend/src/dataloaders/LoginLoader.ts
index b504affe..ec7625f6 100644
--- a/frontend/src/dataloaders/LoginLoader.ts
+++ b/frontend/src/dataloaders/LoginLoader.ts
@@ -1,5 +1,5 @@
import {User} from "../utils/ApiInterfaces.ts";
-import apiFetch from "../utils/ApiFetch.ts";
+import apiFetch from "../utils/api/ApiFetch.ts";
export const LOGIN_ROUTER_ID = "login";
diff --git a/frontend/src/dataloaders/SharedFunctions.ts b/frontend/src/dataloaders/SharedFunctions.ts
index 252fbb1a..cbc60806 100644
--- a/frontend/src/dataloaders/SharedFunctions.ts
+++ b/frontend/src/dataloaders/SharedFunctions.ts
@@ -1,5 +1,5 @@
import {CompleteProject, Group, Project, Subject, Submission} from "../utils/ApiInterfaces.ts";
-import apiFetch from "../utils/ApiFetch.ts";
+import apiFetch from "../utils/api/ApiFetch.ts";
export enum teacherStudentRole {
STUDENT = "student",
diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx
index ca0f1260..28d210e7 100644
--- a/frontend/src/main.tsx
+++ b/frontend/src/main.tsx
@@ -25,6 +25,7 @@ import CoursesViewTeacher from "./pages/teacher/CoursesViewTeacher.tsx";
import {CreateProject} from "./pages/teacher/CreateProject.tsx";
import CreateCourse from "./pages/teacher/CreateCourse.tsx";
import projectsTeacherLoader, {PROJECTS_TEACHER_ROUTER_ID} from "./dataloaders/projectsTeacherLoader.ts";
+import Test from "./pages/Test.tsx";
const router = createBrowserRouter(
createRoutesFromElements(
@@ -33,6 +34,7 @@ const router = createBrowserRouter(
} loader={loginLoader}
errorElement={}/>
}/>
+ }/>
{/* Protected routes */}
}>
diff --git a/frontend/src/pages/Test.tsx b/frontend/src/pages/Test.tsx
new file mode 100644
index 00000000..626d973e
--- /dev/null
+++ b/frontend/src/pages/Test.tsx
@@ -0,0 +1,12 @@
+import {projectGroup} from "../utils/api/Groups.ts";
+
+export default function Test () {
+ function clickEvent () {
+ console.log(projectGroup(2))
+ }
+
+ return (
+
Welcome on this test page, click the button below to test te function
+
+ )
+}
\ No newline at end of file
diff --git a/frontend/src/pages/login/LoginScreen.tsx b/frontend/src/pages/login/LoginScreen.tsx
index e407a104..0f9beba1 100644
--- a/frontend/src/pages/login/LoginScreen.tsx
+++ b/frontend/src/pages/login/LoginScreen.tsx
@@ -35,7 +35,7 @@ const ticketLogin = async (ticket: string, setUser: React.Dispatch {
- return (data && data.user_id && data.user_name && data.user_email && data.user_roles);
+ return (data && data.id && data.name && data.email && data.roles);
}
diff --git a/frontend/src/pages/root.tsx b/frontend/src/pages/root.tsx
index a9c2d7b2..ea446625 100644
--- a/frontend/src/pages/root.tsx
+++ b/frontend/src/pages/root.tsx
@@ -2,17 +2,17 @@ import {JSX} from "react";
import useAuth from "../hooks/useAuth.ts";
import {Navigate} from "react-router-dom";
-export const DEBUG: boolean = false; // should always be false on the repo.
+export const DEBUG: boolean = true; // should always be false on the repo.
export default function Root(): JSX.Element {
const {user} = useAuth()
let to: string = "/error"
- if (user?.user_roles.includes('TEACHER')) {
+ if (user?.roles.includes('TEACHER')) {
to = "/teacher";
- } else if (user?.user_roles.includes('STUDENT')) {
+ } else if (user?.roles.includes('STUDENT')) {
to = "/student";
- } else if (user?.user_roles.includes('ADMIN')) {
+ } else if (user?.roles.includes('ADMIN')) {
to = "/admin";
}
diff --git a/frontend/src/utils/ApiInterfaces.ts b/frontend/src/utils/ApiInterfaces.ts
index ff17b611..ef530a5b 100644
--- a/frontend/src/utils/ApiInterfaces.ts
+++ b/frontend/src/utils/ApiInterfaces.ts
@@ -48,8 +48,8 @@ export interface Token {
}
export interface User {
- user_id: number,
- user_name: string,
- user_email: string,
- user_roles: string[]
+ id: number,
+ name: string,
+ email: string,
+ roles: string[]
}
\ No newline at end of file
diff --git a/frontend/src/utils/ApiFetch.ts b/frontend/src/utils/api/ApiFetch.ts
similarity index 91%
rename from frontend/src/utils/ApiFetch.ts
rename to frontend/src/utils/api/ApiFetch.ts
index 19c8d250..e4934a1d 100644
--- a/frontend/src/utils/ApiFetch.ts
+++ b/frontend/src/utils/api/ApiFetch.ts
@@ -1,4 +1,4 @@
-import {DEBUG} from "../pages/root.tsx";
+import {DEBUG} from "../../pages/root.tsx";
const ApiFetch = async (url: string, options?: RequestInit) => {
diff --git a/frontend/src/utils/api/Groups.ts b/frontend/src/utils/api/Groups.ts
new file mode 100644
index 00000000..54bc3af5
--- /dev/null
+++ b/frontend/src/utils/api/Groups.ts
@@ -0,0 +1,23 @@
+import ApiFetch from "./ApiFetch.ts";
+
+export function joinGroup(groupId: number) {
+ void ApiFetch(`/groups/${groupId}/join`,
+ {method: 'POST', headers: {'Content-Type': 'application/json'}});
+}
+
+export function leaveGroup(groupId: number) {
+ void ApiFetch(`/groups/${groupId}/leave`,
+ {method: 'POST', headers: {'Content-Type': 'application/json'}});
+}
+
+export async function listGroupMembers(groupId: number) {
+ let members = await ApiFetch(`/groups/${groupId}/members`,
+ {method: 'GET', headers: {'Content-Type': 'application/json'}});
+ return members;
+}
+
+export function projectGroup(projectId: number) {
+ let group = void ApiFetch(`/projects/${projectId}/group`,
+ {method: 'GET', headers: {'Content-Type': 'application/json'}});
+ return group;
+}
\ No newline at end of file
diff --git a/frontend/src/utils/api/Login.ts b/frontend/src/utils/api/Login.ts
new file mode 100644
index 00000000..e69de29b
diff --git a/frontend/src/utils/api/Project.ts b/frontend/src/utils/api/Project.ts
new file mode 100644
index 00000000..e69de29b
diff --git a/frontend/src/utils/api/Student.ts b/frontend/src/utils/api/Student.ts
new file mode 100644
index 00000000..e69de29b
diff --git a/frontend/src/utils/api/Subject.ts b/frontend/src/utils/api/Subject.ts
new file mode 100644
index 00000000..e69de29b
diff --git a/frontend/src/utils/api/Submission.ts b/frontend/src/utils/api/Submission.ts
new file mode 100644
index 00000000..e69de29b
diff --git a/frontend/src/utils/api/Teacher.ts b/frontend/src/utils/api/Teacher.ts
new file mode 100644
index 00000000..e69de29b
diff --git a/frontend/src/utils/api/User.ts b/frontend/src/utils/api/User.ts
new file mode 100644
index 00000000..e69de29b
From 32c53f0526923f9d4694dc622e5162c5ba406de3 Mon Sep 17 00:00:00 2001
From: ALBERICLOOS
Date: Sat, 6 Apr 2024 13:20:40 +0200
Subject: [PATCH 16/90] add project student loader
---
frontend/src/dataloaders/ProjectsStudentLoader.ts | 13 +++++++++++++
1 file changed, 13 insertions(+)
create mode 100644 frontend/src/dataloaders/ProjectsStudentLoader.ts
diff --git a/frontend/src/dataloaders/ProjectsStudentLoader.ts b/frontend/src/dataloaders/ProjectsStudentLoader.ts
new file mode 100644
index 00000000..75cb0c67
--- /dev/null
+++ b/frontend/src/dataloaders/ProjectsStudentLoader.ts
@@ -0,0 +1,13 @@
+import {CompleteProject} from "../utils/ApiInterfaces.ts";
+import {projectsLoader, teacherStudentRole} from "./SharedFunctions.ts";
+
+export const PROJECTS_STUDENT_ROUTER_ID = "projects_student";
+
+export interface projectsStudentLoaderObject {
+ projects: CompleteProject[]
+}
+
+export default async function projectsStudentLoader(): Promise {
+ const projects: CompleteProject[] = await projectsLoader(teacherStudentRole.STUDENT);
+ return {projects};
+}
\ No newline at end of file
From ce8881ceb00f3344616703ff938b2bc18abaae81 Mon Sep 17 00:00:00 2001
From: ALBERICLOOS
Date: Sat, 6 Apr 2024 13:22:42 +0200
Subject: [PATCH 17/90] add student loader to main
---
frontend/src/main.tsx | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx
index 28d210e7..c900e1f8 100644
--- a/frontend/src/main.tsx
+++ b/frontend/src/main.tsx
@@ -25,7 +25,7 @@ import CoursesViewTeacher from "./pages/teacher/CoursesViewTeacher.tsx";
import {CreateProject} from "./pages/teacher/CreateProject.tsx";
import CreateCourse from "./pages/teacher/CreateCourse.tsx";
import projectsTeacherLoader, {PROJECTS_TEACHER_ROUTER_ID} from "./dataloaders/projectsTeacherLoader.ts";
-import Test from "./pages/Test.tsx";
+import projectsStudentLoader, {PROJECTS_STUDENT_ROUTER_ID} from "./dataloaders/ProjectsStudentLoader.ts";
const router = createBrowserRouter(
createRoutesFromElements(
@@ -34,7 +34,6 @@ const router = createBrowserRouter(
} loader={loginLoader}
errorElement={}/>
}/>
- }/>
{/* Protected routes */}
}>
@@ -47,15 +46,18 @@ const router = createBrowserRouter(
}>
} loader={studentLoader}/>
- }/>
+ }
+ loader={projectsStudentLoader}/>
}/>
}>
} loader={teacherLoader}/>
- } loader={projectsTeacherLoader}/>
+ }
+ loader={projectsTeacherLoader}/>
}/>
- } /*loader={subjectsTeacherLoader} id={SUBJECT_TEACHER_ROUTER_ID}*//>
+ } /*loader={subjectsTeacherLoader} id={SUBJECT_TEACHER_ROUTER_ID}*//>
}/>
From ff1c76eb38c0bd779b138e66bbb9374bd1715e57 Mon Sep 17 00:00:00 2001
From: ALBERICLOOS
Date: Sat, 6 Apr 2024 13:39:31 +0200
Subject: [PATCH 18/90] add loader to projectview file
---
frontend/src/pages/student/ProjectsViewStudent.tsx | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/frontend/src/pages/student/ProjectsViewStudent.tsx b/frontend/src/pages/student/ProjectsViewStudent.tsx
index 17bd8b6d..dab6fb42 100644
--- a/frontend/src/pages/student/ProjectsViewStudent.tsx
+++ b/frontend/src/pages/student/ProjectsViewStudent.tsx
@@ -3,8 +3,15 @@ import {Header} from "../../components/Header.tsx";
import {Sidebar} from "../../components/Sidebar.tsx";
import {SearchBar} from "../../components/SearchBar.tsx";
import {Table, TableRowProjects} from "../../components/Table.tsx";
+import {studentLoaderObject} from "../../dataloaders/StudentLoader.ts";
+import {useRouteLoaderData} from "react-router-dom";
+import {PROJECTS_STUDENT_ROUTER_ID} from "../../dataloaders/ProjectsStudentLoader.ts";
export default function ProjectsViewStudent(): JSX.Element {
+
+ const data: studentLoaderObject = useRouteLoaderData(PROJECTS_STUDENT_ROUTER_ID) as studentLoaderObject
+ console.log(data)
+
const tableProjectsActive: TableRowProjects[] = [
{
name: "Markov Decision Diagram",
@@ -46,7 +53,8 @@ export default function ProjectsViewStudent(): JSX.Element {
From 0c0dbba51ab53271887b76336af42a69ca9d528f Mon Sep 17 00:00:00 2001
From: ALBERICLOOS
Date: Sat, 6 Apr 2024 13:53:14 +0200
Subject: [PATCH 19/90] add student courses dataloader
---
frontend/src/dataloaders/CoursesStudentLoader.ts | 13 +++++++++++++
frontend/src/main.tsx | 4 +++-
2 files changed, 16 insertions(+), 1 deletion(-)
create mode 100644 frontend/src/dataloaders/CoursesStudentLoader.ts
diff --git a/frontend/src/dataloaders/CoursesStudentLoader.ts b/frontend/src/dataloaders/CoursesStudentLoader.ts
new file mode 100644
index 00000000..2cdbd518
--- /dev/null
+++ b/frontend/src/dataloaders/CoursesStudentLoader.ts
@@ -0,0 +1,13 @@
+import {properSubject} from "../utils/ApiInterfaces.ts";
+import {coursesLoader, teacherStudentRole} from "./SharedFunctions.ts";
+
+export const COURSES_STUDENT_ROUTER_ID = "courses_student";
+
+export interface coursesStudentLoaderObject {
+ courses: properSubject[]
+}
+
+export default async function coursesStudentLoader(): Promise {
+ const courses: properSubject[] = await coursesLoader(teacherStudentRole.STUDENT);
+ return {courses};
+}
\ No newline at end of file
diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx
index c900e1f8..21346521 100644
--- a/frontend/src/main.tsx
+++ b/frontend/src/main.tsx
@@ -26,6 +26,7 @@ import {CreateProject} from "./pages/teacher/CreateProject.tsx";
import CreateCourse from "./pages/teacher/CreateCourse.tsx";
import projectsTeacherLoader, {PROJECTS_TEACHER_ROUTER_ID} from "./dataloaders/projectsTeacherLoader.ts";
import projectsStudentLoader, {PROJECTS_STUDENT_ROUTER_ID} from "./dataloaders/ProjectsStudentLoader.ts";
+import coursesStudentLoader, {COURSES_STUDENT_ROUTER_ID} from './dataloaders/CoursesStudentLoader.ts';
const router = createBrowserRouter(
createRoutesFromElements(
@@ -48,7 +49,8 @@ const router = createBrowserRouter(
} loader={studentLoader}/>
}
loader={projectsStudentLoader}/>
- }/>
+ }
+ loader={coursesStudentLoader}/>
}>
From b208af2c06f8a223295f664be22a52cd96a06db1 Mon Sep 17 00:00:00 2001
From: ALBERICLOOS
Date: Sat, 6 Apr 2024 14:03:15 +0200
Subject: [PATCH 20/90] change coursedataloader
---
frontend/src/dataloaders/SharedFunctions.ts | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/frontend/src/dataloaders/SharedFunctions.ts b/frontend/src/dataloaders/SharedFunctions.ts
index cbc60806..6807baa3 100644
--- a/frontend/src/dataloaders/SharedFunctions.ts
+++ b/frontend/src/dataloaders/SharedFunctions.ts
@@ -1,4 +1,4 @@
-import {CompleteProject, Group, Project, Subject, Submission} from "../utils/ApiInterfaces.ts";
+import {CompleteProject, Group, Project, properSubject, Subject, Submission} from "../utils/ApiInterfaces.ts";
import apiFetch from "../utils/api/ApiFetch.ts";
export enum teacherStudentRole {
@@ -6,6 +6,25 @@ export enum teacherStudentRole {
TEACHER = "teacher"
}
+export async function coursesLoader(role: teacherStudentRole): Promise {
+ const {subjects, projects} = await getAllProjectsAndSubjects(role);
+ if (!Array.isArray(projects) || !Array.isArray(subjects)) {
+ throw Error("Problem loading projects or courses.");
+ }
+ return subjects.map((subject) => {
+ const first_deadline = null; // TODO: add deadlines when needed api endpoints are added.
+ const project = projects.find(project => project.subject_id === subject.subject_id);
+ return {
+ active_projects: projects.filter(project => project.subject_id === subject.subject_id).length,
+ first_deadline: first_deadline,
+ ...project,
+ ...subject
+ }
+ });
+
+
+}
+
export async function projectsLoader(role: teacherStudentRole): Promise {
const {subjects, projects} = await getAllProjectsAndSubjects(role);
if (! Array.isArray(projects) || ! Array.isArray(subjects)) {
From dcd63278c3215e4103690471358166cfefc2514a Mon Sep 17 00:00:00 2001
From: ALBERICLOOS
Date: Sat, 6 Apr 2024 15:17:42 +0200
Subject: [PATCH 21/90] course dataloader teacher
---
.../src/dataloaders/CoursesTeacherLoader.ts | 13 ++++++++++
frontend/src/dataloaders/SharedFunctions.ts | 5 ++--
.../src/dataloaders/SubjectsTeacherLoader.ts | 26 -------------------
frontend/src/main.tsx | 7 ++---
4 files changed, 19 insertions(+), 32 deletions(-)
create mode 100644 frontend/src/dataloaders/CoursesTeacherLoader.ts
delete mode 100644 frontend/src/dataloaders/SubjectsTeacherLoader.ts
diff --git a/frontend/src/dataloaders/CoursesTeacherLoader.ts b/frontend/src/dataloaders/CoursesTeacherLoader.ts
new file mode 100644
index 00000000..4ca3bb8b
--- /dev/null
+++ b/frontend/src/dataloaders/CoursesTeacherLoader.ts
@@ -0,0 +1,13 @@
+import {properSubject} from "../utils/ApiInterfaces.ts";
+import {coursesLoader, teacherStudentRole} from "./SharedFunctions.ts";
+
+export interface subjectsTeacherLoaderObject {
+ courses: properSubject[]
+}
+
+export const COURSES_TEACHER_ROUTER_ID = "courses_teacher";
+
+export default async function coursesTeacherLoader(): Promise {
+ const courses: properSubject[] = await coursesLoader(teacherStudentRole.TEACHER);
+ return {courses};
+}
\ No newline at end of file
diff --git a/frontend/src/dataloaders/SharedFunctions.ts b/frontend/src/dataloaders/SharedFunctions.ts
index 6807baa3..5b21e226 100644
--- a/frontend/src/dataloaders/SharedFunctions.ts
+++ b/frontend/src/dataloaders/SharedFunctions.ts
@@ -13,12 +13,11 @@ export async function coursesLoader(role: teacherStudentRole): Promise {
const first_deadline = null; // TODO: add deadlines when needed api endpoints are added.
- const project = projects.find(project => project.subject_id === subject.subject_id);
return {
active_projects: projects.filter(project => project.subject_id === subject.subject_id).length,
first_deadline: first_deadline,
- ...project,
- ...subject
+ subject_id: subject.subject_id,
+ subject_name: subject.subject_name
}
});
diff --git a/frontend/src/dataloaders/SubjectsTeacherLoader.ts b/frontend/src/dataloaders/SubjectsTeacherLoader.ts
deleted file mode 100644
index a6d08357..00000000
--- a/frontend/src/dataloaders/SubjectsTeacherLoader.ts
+++ /dev/null
@@ -1,26 +0,0 @@
-import {properSubject} from "../utils/ApiInterfaces.ts";
-
-export interface subjectsTeacherLoaderObject {
- subjects: properSubject[]
-}
-
-// export const SUBJECT_TEACHER_ROUTER_ID = "subjectTeacher";
-
-export default async function subjectsTeacherLoader(): Promise {
- // const temp: projectsAndSubjects = await getAllProjectsAndSubjects(teacherStudentRole.TEACHER);
- // const subjects: Subject[] = temp.subjects;
- // const projects: Project[] = temp.projects;
-
- // const p_subjects: properSubject[] = subjects.map(subject => {
- // const active_projects = projects.filter(project =>
- // project.archived && project.subject_id === subject.id
- // );
- // return {
- // id: subject.id,
- // name: subject.name,
- // active_projects: active_projects.length,
- // first_deadline: null // TODO: add deadlines when needed api endpoints are added.
- // };
- // });
- return {"subjects": []}
-}
\ No newline at end of file
diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx
index 21346521..982d6dfb 100644
--- a/frontend/src/main.tsx
+++ b/frontend/src/main.tsx
@@ -11,7 +11,7 @@ import HomeTeacher from "./pages/teacher/HomeTeacher.tsx";
import studentLoader, {STUDENT_ROUTER_ID} from "./dataloaders/StudentLoader.ts";
import Unauthorized from "./components/authentication/Unauthorized.tsx";
import teacherLoader, {TEACHER_ROUTER_ID} from "./dataloaders/TeacherLoader.ts";
-// import subjectsTeacherLoader, {SUBJECT_TEACHER_ROUTER_ID} from "./dataloaders/SubjectsTeacherLoader.ts";
+// import coursesTeacherLoader, {SUBJECT_TEACHER_ROUTER_ID} from "./dataloaders/CoursesTeacherLoader.ts";
import loginLoader, {LOGIN_ROUTER_ID} from "./dataloaders/LoginLoader.ts";
import ErrorLogin from "./components/authentication/ErrorLogin.tsx";
import ProjectsViewStudent from "./pages/student/ProjectsViewStudent.tsx";
@@ -27,6 +27,7 @@ import CreateCourse from "./pages/teacher/CreateCourse.tsx";
import projectsTeacherLoader, {PROJECTS_TEACHER_ROUTER_ID} from "./dataloaders/projectsTeacherLoader.ts";
import projectsStudentLoader, {PROJECTS_STUDENT_ROUTER_ID} from "./dataloaders/ProjectsStudentLoader.ts";
import coursesStudentLoader, {COURSES_STUDENT_ROUTER_ID} from './dataloaders/CoursesStudentLoader.ts';
+import coursesTeacherLoader, {COURSES_TEACHER_ROUTER_ID} from "./dataloaders/CoursesTeacherLoader.ts";
const router = createBrowserRouter(
createRoutesFromElements(
@@ -58,8 +59,8 @@ const router = createBrowserRouter(
}
loader={projectsTeacherLoader}/>
}/>
- } /*loader={subjectsTeacherLoader} id={SUBJECT_TEACHER_ROUTER_ID}*//>
+ } loader={coursesTeacherLoader}/>
}/>
From 99ce8c57ee89667f87b44c81050f6df320800c26 Mon Sep 17 00:00:00 2001
From: ALBERICLOOS
Date: Sat, 6 Apr 2024 15:26:51 +0200
Subject: [PATCH 22/90] add data to view components
---
frontend/src/pages/student/CoursesViewStudent.tsx | 5 +++++
frontend/src/pages/teacher/CoursesViewTeacher.tsx | 9 ++++-----
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/frontend/src/pages/student/CoursesViewStudent.tsx b/frontend/src/pages/student/CoursesViewStudent.tsx
index a1148a22..847d2003 100644
--- a/frontend/src/pages/student/CoursesViewStudent.tsx
+++ b/frontend/src/pages/student/CoursesViewStudent.tsx
@@ -4,9 +4,14 @@ import {Sidebar} from "../../components/Sidebar.tsx";
import '../../assets/styles/students_components.css'
import {SearchBar} from "../../components/SearchBar.tsx";
import {Table, TableRowCourses} from "../../components/Table.tsx";
+import {useRouteLoaderData} from "react-router-dom";
+import {COURSES_STUDENT_ROUTER_ID, coursesStudentLoaderObject} from "../../dataloaders/CoursesStudentLoader.ts";
export default function CoursesViewStudent(): JSX.Element {
+ const data: coursesStudentLoaderObject = useRouteLoaderData(COURSES_STUDENT_ROUTER_ID) as coursesStudentLoaderObject
+ console.log(data)
+
const tableCoursesActive: TableRowCourses[] = [
{
name: "Automaten, berekenbaarheid & complexiteit",
diff --git a/frontend/src/pages/teacher/CoursesViewTeacher.tsx b/frontend/src/pages/teacher/CoursesViewTeacher.tsx
index 6695eed8..6a30bba6 100644
--- a/frontend/src/pages/teacher/CoursesViewTeacher.tsx
+++ b/frontend/src/pages/teacher/CoursesViewTeacher.tsx
@@ -4,14 +4,13 @@ import {Header} from "../../components/Header.tsx";
import {Sidebar} from "../../components/Sidebar.tsx";
import {SearchBar} from "../../components/SearchBar.tsx";
import {RegularATag} from "../../components/RegularATag.tsx";
-
-// import {useRouteLoaderData} from "react-router-dom";
-// import {SUBJECT_TEACHER_ROUTER_ID, subjectsTeacherLoaderObject} from "../../dataloaders/SubjectsTeacherLoader.ts";
+import {COURSES_TEACHER_ROUTER_ID, coursesTeacherLoaderObject} from "../../dataloaders/CoursesTeacherLoader.ts";
+import {useRouteLoaderData} from "react-router-dom";
export default function CoursesViewTeacher(): JSX.Element {
- // const data= useRouteLoaderData(SUBJECT_TEACHER_ROUTER_ID) as subjectsTeacherLoaderObject;
- // console.log(data);
+ const data = useRouteLoaderData(COURSES_TEACHER_ROUTER_ID) as coursesTeacherLoaderObject;
+ console.log(data);
const tableCoursesActive: TableRowCourses[] = [
{
From 934f6f60eb040c4f291b9ee6a166a0d6dc46d1e9 Mon Sep 17 00:00:00 2001
From: ALBERICLOOS
Date: Sat, 6 Apr 2024 15:27:06 +0200
Subject: [PATCH 23/90] change return value
---
frontend/src/dataloaders/CoursesTeacherLoader.ts | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/frontend/src/dataloaders/CoursesTeacherLoader.ts b/frontend/src/dataloaders/CoursesTeacherLoader.ts
index 4ca3bb8b..ce501537 100644
--- a/frontend/src/dataloaders/CoursesTeacherLoader.ts
+++ b/frontend/src/dataloaders/CoursesTeacherLoader.ts
@@ -1,13 +1,13 @@
import {properSubject} from "../utils/ApiInterfaces.ts";
import {coursesLoader, teacherStudentRole} from "./SharedFunctions.ts";
-export interface subjectsTeacherLoaderObject {
+export interface coursesTeacherLoaderObject {
courses: properSubject[]
}
export const COURSES_TEACHER_ROUTER_ID = "courses_teacher";
-export default async function coursesTeacherLoader(): Promise {
+export default async function coursesTeacherLoader(): Promise {
const courses: properSubject[] = await coursesLoader(teacherStudentRole.TEACHER);
return {courses};
}
\ No newline at end of file
From c4a5cb78b99cf98e69a1b194dda94a5e74bcf269 Mon Sep 17 00:00:00 2001
From: ALBERICLOOS
Date: Sat, 6 Apr 2024 15:30:55 +0200
Subject: [PATCH 24/90] no p tags in p tags
---
frontend/src/components/Header.tsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/frontend/src/components/Header.tsx b/frontend/src/components/Header.tsx
index eb041bf0..204ed32c 100644
--- a/frontend/src/components/Header.tsx
+++ b/frontend/src/components/Header.tsx
@@ -11,7 +11,7 @@ export function Header(props: { page_title: string, home: string }): JSX.Element
- {props.page_title}
+