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

Commit

Permalink
Change session dependency by middleware in student routes #122
Browse files Browse the repository at this point in the history
  • Loading branch information
lbarraga committed Apr 2, 2024
1 parent 19a40f2 commit edaee9a
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions backend/routes/student.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session
from starlette.requests import Request

from db.sessions import get_session
from domain.logic.project import get_projects_of_student
from domain.logic.subject import add_student_to_subject, get_subjects_of_student
from domain.models.ProjectDataclass import ProjectDataclass
Expand All @@ -15,18 +14,18 @@

@student_router.get("/student/subjects", tags=[Tags.STUDENT], summary="Get all subjects of the student.")
def subjects_of_student_get(
session: Session = Depends(get_session),
request: Request,
student: StudentDataclass = Depends(get_authenticated_student),
) -> list[SubjectDataclass]:
return get_subjects_of_student(session, student.id)
return get_subjects_of_student(request.state.session, student.id)


@student_router.get("/student/projects", tags=[Tags.STUDENT], summary="Get all projects of the student.")
def projects_of_student_get(
session: Session = Depends(get_session),
request: Request,
student: StudentDataclass = Depends(get_authenticated_student),
) -> list[ProjectDataclass]:
return get_projects_of_student(session, student.id)
return get_projects_of_student(request.state.session, student.id)


@student_router.post(
Expand All @@ -36,7 +35,7 @@ def projects_of_student_get(
)
def student_subject_join(
subject_id: int,
session: Session = Depends(get_session),
request: Request,
student: StudentDataclass = Depends(get_authenticated_student),
) -> None:
add_student_to_subject(session, student.id, subject_id)
add_student_to_subject(request.state.session, student.id, subject_id)

0 comments on commit edaee9a

Please sign in to comment.