This repository has been archived by the owner on Sep 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add routes for joining/leaving a group
- Loading branch information
Showing
5 changed files
with
58 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from fastapi import APIRouter, Depends | ||
from sqlalchemy.orm import Session | ||
|
||
from db.sessions import get_session | ||
from domain.logic.group import add_student_to_group, remove_student_from_group | ||
from domain.models.StudentDataclass import StudentDataclass | ||
from routes.dependencies.role_dependencies import ensure_student_authorized_for_group | ||
|
||
group_router = APIRouter() | ||
|
||
|
||
@group_router.post("/groups/{group_id}/join") | ||
def group_join( | ||
group_id: int, | ||
student: StudentDataclass = Depends(ensure_student_authorized_for_group), | ||
session: Session = Depends(get_session), | ||
) -> None: | ||
add_student_to_group(session, student.id, group_id) | ||
|
||
|
||
@group_router.post("/groups/{group_id}/leave") | ||
def group_leave( | ||
group_id: int, | ||
student: StudentDataclass = Depends(ensure_student_authorized_for_group), | ||
session: Session = Depends(get_session), | ||
) -> None: | ||
remove_student_from_group(session, student.id, group_id) |