Custom client for UTBM UV API calls

This commit is contained in:
imperosol
2025-01-21 13:57:18 +01:00
parent 85c8b7d11c
commit 6d519e3a07
3 changed files with 57 additions and 26 deletions

View File

@ -10,13 +10,13 @@ from ninja_extra.pagination import PageNumberPaginationExtra, PaginatedResponseS
from core.auth.api_permissions import HasPerm
from pedagogy.models import UV
from pedagogy.schemas import SimpleUvSchema, UvFilterSchema, UvSchema
from pedagogy.utbm_api import find_uv
from pedagogy.utbm_api import UtbmApiClient
@api_controller("/uv")
class UvController(ControllerBase):
@route.get(
"/{year}/{code}",
"/{code}",
permissions=[
# this route will almost always be called in the context
# of a UV creation/edition
@ -26,10 +26,14 @@ class UvController(ControllerBase):
response=UvSchema,
)
def fetch_from_utbm_api(
self, year: Annotated[int, Ge(2010)], code: str, lang: Query[str] = "fr"
self,
code: str,
lang: Query[str] = "fr",
year: Query[Annotated[int, Ge(2010)] | None] = None,
):
"""Fetch UV data from the UTBM API and returns it after some parsing."""
res = find_uv(lang, year, code)
with UtbmApiClient() as client:
res = client.find_uv(lang, code, year)
if res is None:
raise NotFound
return res