76b1e712b9
Works through every numbered item in NextSteps260913.md section 3, plus the three known verification issues in section 4.1. Surface what the backend already computed: - 3.1 render surplus_advice in PlanResults, mirroring the shortfall remedies - 3.2 surface VacationBalance.is_assumed so assumed statutory years are visible - 3.3 age-4 expiry given the proposed plan, via a new Age4Projection reusing the existing _age4_projections arithmetic (Dashboard stat verified, not rebuilt) Calendar cluster (one pass over the holiday data): - new GET /api/calendar/days exposing roda dagar, klamdagar and day overrides, paginated four years at a time - 3.4 shade roda dagar/klamdagar, with R/K badges so colour is not the only signal - 3.6 click-to-override behind an explicit mode toggle, leaving drag multi-select intact - 3.7 click month/year to advance - 3.8 per-year red-days list in Settings, statutory days plus overrides i18n: - 3.5 five backend-generated Swedish surfaces converted to message_key + data, following the tips_service pattern; old string fields replaced, not kept Flexible wishes (3.9): - PLANNING_ENGINE_SPEC section 10: window_mode, candidate search, cost function, deterministic tie-break, two-pass ordering, test matrix rows 15-24 - backend: entity, migration 006, _FULL_SCHEMA sync, repository, allocator - frontend: season-preset toggle in WishEditor, unplaced outcome rendering Fixes (4.1): - pin typecheck to the local tsc rather than npx resolving a newer TypeScript - ignore generated coverage/ and dist/ in the ESLint flat config - fix the flaky usePlanApply test properly, with waitFor rather than a retry Tests: backend 361 -> 404, frontend 540 -> 704. Coverage 89.47% -> 96.52% lines. Not yet verified in a browser. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RXMhc9nT6sNz1SL4j8dznL
107 lines
4.3 KiB
Python
107 lines
4.3 KiB
Python
"""HTTP routes for leave wishes.
|
|
|
|
Routers stay thin: validate via Pydantic, call the service, map domain errors
|
|
to HTTP. Business logic (recurrence/parent_mode/goal_override validation,
|
|
month-day range checks) lives in LeaveWishService. See PLANNING_ENGINE_SPEC.md §4.
|
|
"""
|
|
|
|
from uuid import UUID
|
|
|
|
from fastapi import APIRouter, HTTPException, status
|
|
|
|
from app.dependencies import LeaveWishServiceDep
|
|
from app.models.leave_wish import (
|
|
LeaveWishCreate,
|
|
LeaveWishResponse,
|
|
LeaveWishUpdate,
|
|
)
|
|
from app.utils.errors import NotFoundError, ValidationError
|
|
|
|
router = APIRouter(prefix="/api/leave-wishes", tags=["leave-wishes"])
|
|
|
|
|
|
@router.post("", response_model=LeaveWishResponse, status_code=status.HTTP_201_CREATED)
|
|
async def create_leave_wish(
|
|
payload: LeaveWishCreate, service: LeaveWishServiceDep
|
|
) -> LeaveWishResponse:
|
|
try:
|
|
entity = await service.create(
|
|
workspace_id=payload.workspace_id,
|
|
child_id=payload.child_id,
|
|
name=payload.name,
|
|
window_start_month=payload.window_start_month,
|
|
window_start_day=payload.window_start_day,
|
|
window_end_month=payload.window_end_month,
|
|
window_end_day=payload.window_end_day,
|
|
target_weeks=payload.target_weeks,
|
|
recurrence=payload.recurrence,
|
|
first_year=payload.first_year,
|
|
last_year=payload.last_year,
|
|
priority=payload.priority,
|
|
parent_mode=payload.parent_mode,
|
|
parent_personal_data_uuid=payload.parent_personal_data_uuid,
|
|
goal_override=payload.goal_override,
|
|
window_mode=payload.window_mode,
|
|
)
|
|
except ValidationError as exc:
|
|
raise HTTPException(status.HTTP_422_UNPROCESSABLE_ENTITY, str(exc)) from exc
|
|
return LeaveWishResponse.from_entity(entity)
|
|
|
|
|
|
@router.get("/{workspace_id}", response_model=list[LeaveWishResponse])
|
|
async def list_leave_wishes(
|
|
workspace_id: UUID, service: LeaveWishServiceDep
|
|
) -> list[LeaveWishResponse]:
|
|
"""List all leave wishes for a workspace. Matches PLANNING_ENGINE_SPEC.md §4
|
|
(`GET /api/leave-wishes/{workspace_id}` — list-by-workspace, not get-by-id)."""
|
|
entities = await service.list_for_workspace(workspace_id)
|
|
return [LeaveWishResponse.from_entity(e) for e in entities]
|
|
|
|
|
|
@router.put("/{leave_wish_id}", response_model=LeaveWishResponse)
|
|
async def update_leave_wish(
|
|
leave_wish_id: UUID,
|
|
payload: LeaveWishUpdate,
|
|
service: LeaveWishServiceDep,
|
|
) -> LeaveWishResponse:
|
|
fields_set = payload.model_fields_set
|
|
try:
|
|
entity = await service.update(
|
|
leave_wish_id=leave_wish_id,
|
|
child_id=payload.child_id,
|
|
name=payload.name,
|
|
window_start_month=payload.window_start_month,
|
|
window_start_day=payload.window_start_day,
|
|
window_end_month=payload.window_end_month,
|
|
window_end_day=payload.window_end_day,
|
|
target_weeks=payload.target_weeks,
|
|
recurrence=payload.recurrence,
|
|
first_year=payload.first_year,
|
|
last_year=payload.last_year,
|
|
priority=payload.priority,
|
|
parent_mode=payload.parent_mode,
|
|
parent_personal_data_uuid=payload.parent_personal_data_uuid,
|
|
goal_override=payload.goal_override,
|
|
window_mode=payload.window_mode,
|
|
_clear_child_id="child_id" in fields_set and payload.child_id is None,
|
|
_clear_last_year="last_year" in fields_set and payload.last_year is None,
|
|
_clear_parent_personal_data_uuid=(
|
|
"parent_personal_data_uuid" in fields_set
|
|
and payload.parent_personal_data_uuid is None
|
|
),
|
|
_clear_goal_override=("goal_override" in fields_set and payload.goal_override is None),
|
|
)
|
|
except ValidationError as exc:
|
|
raise HTTPException(status.HTTP_422_UNPROCESSABLE_ENTITY, str(exc)) from exc
|
|
except NotFoundError as exc:
|
|
raise HTTPException(status.HTTP_404_NOT_FOUND, str(exc)) from exc
|
|
return LeaveWishResponse.from_entity(entity)
|
|
|
|
|
|
@router.delete("/{leave_wish_id}", status_code=status.HTTP_204_NO_CONTENT)
|
|
async def delete_leave_wish(leave_wish_id: UUID, service: LeaveWishServiceDep) -> None:
|
|
try:
|
|
await service.delete(leave_wish_id)
|
|
except NotFoundError as exc:
|
|
raise HTTPException(status.HTTP_404_NOT_FOUND, str(exc)) from exc
|