64734ae6e7
Starlette renamed HTTP_422_UNPROCESSABLE_ENTITY to HTTP_422_UNPROCESSABLE_CONTENT and now warns on the old spelling; the value is unchanged at 422, so the 20 call sites in the routers move over with no wire-format or frontend impact. Alembic >=1.16 supersedes version_path_separator with path_separator, which governs both prepend_sys_path and version_locations, and warns when it is absent. Together this takes pytest from 26 deprecation warnings to 6. The remainder are slowapi calling asyncio.iscoroutinefunction; they are left visible deliberately, with no filterwarnings entry, as a reminder to revisit once upstream ships a fix. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
54 lines
2.1 KiB
Python
54 lines
2.1 KiB
Python
"""HTTP routes for vacation days.
|
|
|
|
Routers stay thin: validate via Pydantic, call the service, map domain errors to
|
|
HTTP. This is the REFERENCE router — copy this shape for other entities.
|
|
"""
|
|
|
|
from uuid import UUID
|
|
|
|
from fastapi import APIRouter, HTTPException, status
|
|
|
|
from app.dependencies import VacationDaysServiceDep, WorkspaceIdDep, WorkspaceScopeDep
|
|
from app.models.vacation_days import VacationDaysCreate, VacationDaysResponse
|
|
from app.utils.errors import NotFoundError, ValidationError
|
|
|
|
router = APIRouter(prefix="/api/vacation-days", tags=["vacation-days"])
|
|
|
|
|
|
@router.post("", response_model=VacationDaysResponse, status_code=status.HTTP_201_CREATED)
|
|
async def upsert_vacation_days(
|
|
payload: VacationDaysCreate, service: VacationDaysServiceDep, scope: WorkspaceScopeDep
|
|
) -> VacationDaysResponse:
|
|
scope.check_workspace(payload.workspace_id)
|
|
await scope.check_member(payload.personal_data_uuid)
|
|
try:
|
|
entity = await service.upsert(
|
|
personal_data_uuid=payload.personal_data_uuid,
|
|
workspace_id=payload.workspace_id,
|
|
year=payload.year,
|
|
total_days=payload.total_days,
|
|
saved_days_in=payload.saved_days_in,
|
|
)
|
|
except ValidationError as exc:
|
|
raise HTTPException(status.HTTP_422_UNPROCESSABLE_CONTENT, str(exc)) from exc
|
|
return VacationDaysResponse.from_entity(entity)
|
|
|
|
|
|
@router.get("/{vacation_days_id}", response_model=VacationDaysResponse)
|
|
async def get_vacation_days(
|
|
vacation_days_id: UUID, service: VacationDaysServiceDep, scope: WorkspaceScopeDep
|
|
) -> VacationDaysResponse:
|
|
try:
|
|
entity = await service.get(vacation_days_id, workspace_id=scope.workspace_id)
|
|
except NotFoundError as exc:
|
|
raise HTTPException(status.HTTP_404_NOT_FOUND, str(exc)) from exc
|
|
return VacationDaysResponse.from_entity(entity)
|
|
|
|
|
|
@router.get("/workspace/{workspace_id}", response_model=list[VacationDaysResponse])
|
|
async def list_vacation_days(
|
|
workspace_id: WorkspaceIdDep, service: VacationDaysServiceDep
|
|
) -> list[VacationDaysResponse]:
|
|
entities = await service.list_for_workspace(workspace_id)
|
|
return [VacationDaysResponse.from_entity(e) for e in entities]
|