4d70c8950d
`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>
65 lines
2.3 KiB
Python
65 lines
2.3 KiB
Python
"""HTTP routes for planned-day exclusions.
|
|
|
|
Routers stay thin: validate via Pydantic, call the service, map domain
|
|
errors to HTTP.
|
|
"""
|
|
|
|
from uuid import UUID
|
|
|
|
from fastapi import APIRouter, HTTPException, status
|
|
|
|
from app.dependencies import (
|
|
PlannedDayExclusionServiceDep,
|
|
WorkspaceIdDep,
|
|
WorkspaceScopeDep,
|
|
)
|
|
from app.models.planned_day_exclusion import (
|
|
PlannedDayExclusionCreate,
|
|
PlannedDayExclusionResponse,
|
|
)
|
|
from app.utils.errors import NotFoundError, ValidationError
|
|
|
|
router = APIRouter(prefix="/api/planned-day-exclusions", tags=["planned-day-exclusions"])
|
|
|
|
|
|
@router.post("", response_model=PlannedDayExclusionResponse, status_code=status.HTTP_201_CREATED)
|
|
async def create_planned_day_exclusion(
|
|
payload: PlannedDayExclusionCreate,
|
|
service: PlannedDayExclusionServiceDep,
|
|
scope: WorkspaceScopeDep,
|
|
) -> PlannedDayExclusionResponse:
|
|
scope.check_workspace(payload.workspace_id)
|
|
await scope.check_child(payload.child_id)
|
|
await scope.check_member(payload.parent_personal_data_uuid)
|
|
try:
|
|
entity = await service.exclude(
|
|
workspace_id=payload.workspace_id,
|
|
child_id=payload.child_id,
|
|
parent_personal_data_uuid=payload.parent_personal_data_uuid,
|
|
day=payload.date,
|
|
)
|
|
except ValidationError as exc:
|
|
raise HTTPException(status.HTTP_422_UNPROCESSABLE_CONTENT, str(exc)) from exc
|
|
return PlannedDayExclusionResponse.from_entity(entity)
|
|
|
|
|
|
@router.get("/workspace/{workspace_id}", response_model=list[PlannedDayExclusionResponse])
|
|
async def list_planned_day_exclusions(
|
|
workspace_id: WorkspaceIdDep, service: PlannedDayExclusionServiceDep
|
|
) -> list[PlannedDayExclusionResponse]:
|
|
entities = await service.list_for_workspace(workspace_id)
|
|
return [PlannedDayExclusionResponse.from_entity(e) for e in entities]
|
|
|
|
|
|
@router.delete("/{exclusion_id}", status_code=status.HTTP_204_NO_CONTENT)
|
|
async def delete_planned_day_exclusion(
|
|
exclusion_id: UUID,
|
|
service: PlannedDayExclusionServiceDep,
|
|
scope: WorkspaceScopeDep,
|
|
) -> None:
|
|
"""Un-exclude the day: the planner may place leave here again."""
|
|
try:
|
|
await service.delete(exclusion_id, workspace_id=scope.workspace_id)
|
|
except NotFoundError as exc:
|
|
raise HTTPException(status.HTTP_404_NOT_FOUND, str(exc)) from exc
|