Bugfixes in dashboard and calendar

This commit is contained in:
2026-06-14 19:02:20 +02:00
parent 566595984f
commit d556ce0f6f
6 changed files with 699 additions and 31 deletions
+27 -15
View File
@@ -1,6 +1,5 @@
"""HTTP routes for planned leave days (calendar planning)."""
from datetime import date
from uuid import UUID
from fastapi import APIRouter, HTTPException, Query, status
@@ -9,6 +8,7 @@ from app.dependencies import CurrentUserDep, PlanningServiceDep
from app.models.planned_leave import (
PlannedLeaveDayCreate,
PlannedLeaveDayResponse,
PlannedLeaveDayUpdate,
)
from app.utils.errors import NotFoundError, ValidationError
@@ -39,6 +39,16 @@ async def create_planned_day(
raise HTTPException(status.HTTP_422_UNPROCESSABLE_ENTITY, str(exc)) from exc
@router.get("", response_model=list[PlannedLeaveDayResponse])
async def list_planned_days(
service: PlanningServiceDep,
_current_user: CurrentUserDep,
child_id: UUID = Query(...),
) -> list[PlannedLeaveDayResponse]:
days = await service.list_by_child(child_id)
return [_to_response(d) for d in days]
@router.get("/{planned_leave_day_id}", response_model=PlannedLeaveDayResponse)
async def get_planned_day(
planned_leave_day_id: UUID,
@@ -62,20 +72,22 @@ async def list_planned_days_by_workspace(
return [_to_response(d) for d in days]
@router.get("/range", response_model=list[PlannedLeaveDayResponse])
async def list_planned_days_by_range(
workspace_id: UUID = Query(...),
child_id: UUID = Query(...),
start_date: date = Query(...),
end_date: date = Query(...),
service: PlanningServiceDep = None,
_current_user: CurrentUserDep = None,
) -> list[PlannedLeaveDayResponse]:
# Inject dependencies manually for query parameters
# Since we can't easily pass Query params with FastAPI dependencies,
# we'll need to inject them differently
pass
@router.put("/{planned_leave_day_id}", response_model=PlannedLeaveDayResponse)
async def update_planned_day(
planned_leave_day_id: UUID,
payload: PlannedLeaveDayUpdate,
service: PlanningServiceDep,
_current_user: CurrentUserDep,
) -> PlannedLeaveDayResponse:
try:
day = await service.update(
planned_leave_day_id,
day_type=payload.day_type,
is_dubbeldag=payload.is_dubbeldag,
)
return _to_response(day)
except NotFoundError as exc:
raise HTTPException(status.HTTP_404_NOT_FOUND, str(exc)) from exc
@router.delete("/{planned_leave_day_id}", status_code=status.HTTP_204_NO_CONTENT)
+22
View File
@@ -91,3 +91,25 @@ class PlanningService:
if entity is None:
raise NotFoundError(f"PlannedLeaveDay {planned_leave_day_id} not found")
return entity
async def list_by_child(self, child_id: UUID) -> list[PlannedLeaveDay]:
"""Get all planned days for a child across workspaces."""
return await self._repo.list(child_id=child_id)
async def update(
self,
planned_leave_day_id: UUID,
day_type: str | None = None,
is_dubbeldag: bool | None = None,
) -> PlannedLeaveDay:
"""Update a planned day (partial update)."""
entity = await self._repo.get_by_id(planned_leave_day_id)
if entity is None:
raise NotFoundError(f"PlannedLeaveDay {planned_leave_day_id} not found")
if day_type is not None:
entity.day_type = day_type
if is_dubbeldag is not None:
entity.is_dubbeldag = is_dubbeldag
return await self._repo.update(planned_leave_day_id, entity)
+113
View File
@@ -226,3 +226,116 @@ class TestPlanningService:
assert vacation.day_type == "vacation"
assert lagsta.day_type == "lagsta"
assert sjuk.day_type == "sjukpenning"
async def test_list_by_child(
self,
planning_service: PlanningService,
seeded_ids: SeededIds,
) -> None:
"""List all planned days for a child."""
child_id = seeded_ids.child_id
d1 = await planning_service.add_planned_day(
workspace_id=seeded_ids.workspace_id,
child_id=child_id,
parent_personal_data_uuid=seeded_ids.personal_data_uuid,
date=date(2026, 6, 15),
day_type="vacation",
)
d2 = await planning_service.add_planned_day(
workspace_id=seeded_ids.workspace_id,
child_id=child_id,
parent_personal_data_uuid=seeded_ids.personal_data_uuid,
date=date(2026, 6, 16),
day_type="lagsta",
)
result = await planning_service.list_by_child(child_id)
ids = {d.id for d in result}
assert d1.id in ids
assert d2.id in ids
async def test_list_by_child_empty(
self,
planning_service: PlanningService,
) -> None:
"""Listing a child with no planned days returns empty."""
result = await planning_service.list_by_child(uuid4())
assert result == []
async def test_update_planned_day_day_type(
self,
planning_service: PlanningService,
seeded_ids: SeededIds,
) -> None:
"""Update the day_type of a planned day."""
created = await planning_service.add_planned_day(
workspace_id=seeded_ids.workspace_id,
child_id=seeded_ids.child_id,
parent_personal_data_uuid=seeded_ids.personal_data_uuid,
date=date(2026, 6, 15),
day_type="vacation",
)
updated = await planning_service.update(
created.id,
day_type="lagsta",
)
assert updated.day_type == "lagsta"
assert updated.date == date(2026, 6, 15)
async def test_update_planned_day_is_dubbeldag(
self,
planning_service: PlanningService,
seeded_ids: SeededIds,
) -> None:
"""Update the is_dubbeldag flag of a planned day."""
created = await planning_service.add_planned_day(
workspace_id=seeded_ids.workspace_id,
child_id=seeded_ids.child_id,
parent_personal_data_uuid=seeded_ids.personal_data_uuid,
date=date(2026, 6, 15),
day_type="vacation",
is_dubbeldag=False,
)
updated = await planning_service.update(
created.id,
is_dubbeldag=True,
)
assert updated.is_dubbeldag is True
assert updated.day_type == "vacation"
async def test_update_planned_day_both_fields(
self,
planning_service: PlanningService,
seeded_ids: SeededIds,
) -> None:
"""Update both day_type and is_dubbeldag."""
created = await planning_service.add_planned_day(
workspace_id=seeded_ids.workspace_id,
child_id=seeded_ids.child_id,
parent_personal_data_uuid=seeded_ids.personal_data_uuid,
date=date(2026, 6, 15),
day_type="vacation",
is_dubbeldag=False,
)
updated = await planning_service.update(
created.id,
day_type="sjukpenning",
is_dubbeldag=True,
)
assert updated.day_type == "sjukpenning"
assert updated.is_dubbeldag is True
async def test_update_missing_raises(
self,
planning_service: PlanningService,
) -> None:
"""Updating a missing planned day raises NotFoundError."""
with pytest.raises(NotFoundError):
await planning_service.update(
uuid4(),
day_type="lagsta",
)