Skip to content

Commit

Permalink
get school by id
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexTraveylan committed Aug 28, 2024
1 parent 2e69af9 commit 4dfe337
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion app/api/school/api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
from typing import Annotated

from fastapi import APIRouter, Depends, status
from fastapi import APIRouter, Depends, Path, status

from app.api.links.models import (
SCHOOL_LINK_SERVICE,
Expand Down Expand Up @@ -46,6 +46,20 @@ def get_school_of_user(
return schools


@school_router.get("/{school_id}", status_code=status.HTTP_200_OK)
def get_school_by_id(
school_id: int = Annotated[int, Path(title="school_id")],
) -> SchoolSchemaOut:
with unit_api("Tentative de récupération de l'établissement") as session:
school = SCHOOL_SERVICE.get_or_none(session, id=school_id)
if school is None:
raise RessourceNotFoundException("Établissement non trouvé")

decrypted_school = school.to_decrypted()

return decrypted_school


@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 4dfe337

Please sign in to comment.