Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
aanmaken subjects en projects enpoints die niet meer verbonden zijn a…
Browse files Browse the repository at this point in the history
…an student #45
  • Loading branch information
lbarraga committed Mar 7, 2024
1 parent 2b06770 commit 80a4939
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 20 deletions.
4 changes: 4 additions & 0 deletions backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

from db.errors.database_errors import ActionAlreadyPerformedError, ItemNotFoundError
from routes.errors.authentication import InvalidRoleCredentialsError, StudentNotEnrolledError
from routes.project import project_router
from routes.student import student_router
from routes.subject import subject_router
from routes.teacher import teacher_router
from routes.user import users_router

Expand All @@ -16,6 +18,8 @@
app.include_router(student_router, prefix="/api")
app.include_router(teacher_router, prefix="/api")
app.include_router(users_router, prefix="/api")
app.include_router(project_router, prefix="/api")
app.include_router(subject_router, prefix="/api")


# Koppel de exception handlers
Expand Down
13 changes: 13 additions & 0 deletions backend/routes/project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session

from db.sessions import get_session
from domain.logic.project import get_project
from domain.models.ProjectDataclass import ProjectDataclass

project_router = APIRouter()


@project_router.get("/projects/{project_id}")
def get_subject_project(project_id: int, session: Session = Depends(get_session)) -> ProjectDataclass:
return get_project(session, project_id)
22 changes: 2 additions & 20 deletions backend/routes/student.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
from sqlalchemy.orm import Session

from db.sessions import get_session
from domain.logic.project import get_project, get_projects_of_subject
from domain.logic.subject import get_subject, get_subjects_of_student
from domain.models.ProjectDataclass import ProjectDataclass
from domain.logic.subject import get_subjects_of_student
from domain.models.StudentDataclass import StudentDataclass
from domain.models.SubjectDataclass import SubjectDataclass
from routes.dependencies.role_dependencies import get_authenticated_student, get_authenticated_student_for_subject
from routes.dependencies.role_dependencies import get_authenticated_student

student_router = APIRouter()

Expand All @@ -18,19 +16,3 @@ def subjects_of_student_get(
student: StudentDataclass = Depends(get_authenticated_student),
) -> list[SubjectDataclass]:
return get_subjects_of_student(session, student.id)


@student_router.get("/student/subjects/{subject_id}", dependencies=[Depends(get_authenticated_student)])
def subject_get(subject_id: int, session: Session = Depends(get_session)) -> SubjectDataclass:
return get_subject(session, subject_id)


@student_router.get("/student/subjects/{subject_id}/projects", dependencies=[Depends(get_authenticated_student)])
def get_subject_projects(subject_id: int, session: Session = Depends(get_session)) -> list[ProjectDataclass]:
return get_projects_of_subject(session, subject_id)


@student_router.get("/student/subjects/{subject_id}/projects/{project_id}")
def get_subject_project(subject_id: int, project_id: int, session: Session = Depends(get_session)) -> ProjectDataclass:
get_authenticated_student_for_subject(subject_id)
return get_project(session, project_id)
21 changes: 21 additions & 0 deletions backend/routes/subject.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session

from db.sessions import get_session
from domain.logic.project import get_projects_of_subject
from domain.logic.subject import get_subject
from domain.models.ProjectDataclass import ProjectDataclass
from domain.models.SubjectDataclass import SubjectDataclass
from routes.dependencies.role_dependencies import get_authenticated_student

subject_router = APIRouter()


@subject_router.get("/subjects/{subject_id}", dependencies=[Depends(get_authenticated_student)])
def subject_get(subject_id: int, session: Session = Depends(get_session)) -> SubjectDataclass:
return get_subject(session, subject_id)


@subject_router.get("/subjects/{subject_id}/projects", dependencies=[Depends(get_authenticated_student)])
def get_subject_projects(subject_id: int, session: Session = Depends(get_session)) -> list[ProjectDataclass]:
return get_projects_of_subject(session, subject_id)

0 comments on commit 80a4939

Please sign in to comment.