Files
F-r-ldraledigplannerare/backend/app/routers/preschool_planning_days.py
T
jacobh2 4d70c8950d Stop emitting deprecation warnings from our own backend code
`uv run pytest` reported 26 DeprecationWarnings, 20 of them raised by
code we own. Two independent sources, both already renamed upstream.

Starlette renamed HTTP_422_UNPROCESSABLE_ENTITY to
HTTP_422_UNPROCESSABLE_CONTENT, matching the RFC 9110 name for the
status. Rename all 21 call sites across the twelve routers that raise
it. The numeric value is unchanged at 422, so the wire format and the
frontend's error handling are untouched -- this is forward-compat debt
only. The warnings attributed to fastapi/routing.py were these same
handler frames raising through the dependency call, and go with them.

Alembic >=1.16 supersedes `version_path_separator` with
`path_separator`, which governs both `prepend_sys_path` and
`version_locations`; its absence is what triggered the legacy-splitting
warning on every config load. Swap the key in alembic.ini.

Deliberately not fixing slowapi's `asyncio.iscoroutinefunction` warning
(6 of the 26): it is upstream with no released fix, and no
`filterwarnings` entry is added, so it stays visible as a reminder to
drop the pin once one lands.

Verified from backend/: ruff check and format clean, 893 passed with
coverage at 92%, and the warnings summary is now exactly those 6 slowapi
lines. `alembic upgrade head` runs 001 through 008 without the
path_separator warning.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-20 18:47:29 +02:00

78 lines
2.8 KiB
Python

"""HTTP routes for preschool planning ("studiedagar") days per year.
Routers stay thin: validate via Pydantic, call the service, map domain
errors to HTTP. Scoped per child via `WorkspaceScope.check_child`, which
404s (never 403) on a missing or foreign-workspace child id.
"""
from uuid import UUID
from fastapi import APIRouter, HTTPException, status
from app.dependencies import PreschoolPlanningDaysServiceDep, WorkspaceScopeDep
from app.models.preschool_planning_days import (
PreschoolPlanningDaysPlannedUpdate,
PreschoolPlanningDaysResponse,
PreschoolPlanningDaysTakenUpdate,
)
from app.utils.errors import ValidationError
router = APIRouter(prefix="/api/preschool-planning-days", tags=["preschool-planning-days"])
@router.put("/{child_id}/{year}/planned", response_model=PreschoolPlanningDaysResponse)
async def upsert_planned_days(
child_id: UUID,
year: int,
payload: PreschoolPlanningDaysPlannedUpdate,
service: PreschoolPlanningDaysServiceDep,
scope: WorkspaceScopeDep,
) -> PreschoolPlanningDaysResponse:
child = await scope.check_child(child_id)
try:
entity = await service.upsert_planned(child, year, payload.planned_days)
except ValidationError as exc:
raise HTTPException(status.HTTP_422_UNPROCESSABLE_CONTENT, str(exc)) from exc
return PreschoolPlanningDaysResponse.from_entity(entity)
@router.put("/{child_id}/{year}/taken", response_model=PreschoolPlanningDaysResponse)
async def record_taken_days(
child_id: UUID,
year: int,
payload: PreschoolPlanningDaysTakenUpdate,
service: PreschoolPlanningDaysServiceDep,
scope: WorkspaceScopeDep,
) -> PreschoolPlanningDaysResponse:
child = await scope.check_child(child_id)
try:
entity = await service.record_taken(child, year, payload.taken_days)
except ValidationError as exc:
raise HTTPException(status.HTTP_422_UNPROCESSABLE_CONTENT, str(exc)) from exc
return PreschoolPlanningDaysResponse.from_entity(entity)
@router.get("/{child_id}/{year}", response_model=PreschoolPlanningDaysResponse)
async def get_year(
child_id: UUID,
year: int,
service: PreschoolPlanningDaysServiceDep,
scope: WorkspaceScopeDep,
) -> PreschoolPlanningDaysResponse:
child = await scope.check_child(child_id)
entity = await service.get_by_child_year(child_id, year)
if entity is None:
return PreschoolPlanningDaysResponse.default_for(child, year)
return PreschoolPlanningDaysResponse.from_entity(entity)
@router.get("/{child_id}", response_model=list[PreschoolPlanningDaysResponse])
async def list_years(
child_id: UUID,
service: PreschoolPlanningDaysServiceDep,
scope: WorkspaceScopeDep,
) -> list[PreschoolPlanningDaysResponse]:
await scope.check_child(child_id)
entities = await service.list_for_child(child_id)
return [PreschoolPlanningDaysResponse.from_entity(e) for e in entities]