Files
F-r-ldraledigplannerare/backend/app/routers/planned_day_exclusions.py
T
jacobh2 8cfb9c82c6 Let a day removed from a period stay removed
Taking one day out of a period the planner placed did nothing that
lasted: the period still asked for a full week, so the next sync put the
day straight back. The option was disabled rather than lying about it.

A removed day is now recorded as its own thing — no leave for this
parent, this child, this date — and the planner honours it on every
later sync. It is kept apart from the working-day overrides, which
answer a different question about the calendar rather than about the
plan.

The day belongs to the parent whose band was clicked, so removing one
parent's day leaves their partner's alone; where both parents were to be
off on one funding arrangement, the partner is simply funded on their
own instead. A removed day shortens what the period is asking for rather
than counting as a day the plan failed to find, so the advice about
closing a shortfall does not start arguing for a day nobody wants.

Nothing is removed without a way back: the toast undoes it, and the day
itself is marked in the calendar and offers to restore.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ei7gCZzdd751uZtPzb1Pep
2026-09-19 16:05:17 +02:00

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_ENTITY, 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