Skip to content

Commit

Permalink
get userme schools
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexTraveylan committed Aug 27, 2024
1 parent b2ae86d commit bfec30c
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion app/api/school/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
from app.api.school.models import SCHOOL_SERVICE, School
from app.api.school.schemas import SchoolSchemaIn, SchoolSchemaOut
from app.auth.models import User
from app.auth.token import get_current_user
from app.auth.token import (
UserWithInformations,
get_current_user,
get_current_user_with_informations,
)
from app.database.unit_of_work import unit_api
from app.exceptions import CannotCreateStillExistsException, RessourceNotFoundException

Expand All @@ -23,6 +27,25 @@
)


@school_router.get("/me", status_code=status.HTTP_200_OK)
def get_school_of_user(
current_user: Annotated[
UserWithInformations, Depends(get_current_user_with_informations)
],
) -> list[SchoolSchemaOut]:
with unit_api(
"Tentative de récupération de l'établissement de l'utilisateur"
) as session:
schools = []
for school_id in current_user.school_ids:
school = SCHOOL_SERVICE.get_or_none(session, id=school_id)
if school is None:
raise RessourceNotFoundException("Établissement non trouvé")
schools.append(school.to_decrypted())

return schools


@school_router.get("/", status_code=status.HTTP_200_OK)
def get_all_schools() -> list[SchoolSchemaOut]:
with unit_api("Tentative de récupération de tous les établissements") as session:
Expand Down

0 comments on commit bfec30c

Please sign in to comment.