Give tips a date, a scope per child, and a dismissal that sticks

Three faults, all invisible while the tests passed. Advice was built for the
first child only, so a second child got none. The planned days feeding every
count were fetched once per parent and appended to one list, so a couple's
days were counted twice and every intensity and projection derived from them
was wrong. And dismissing a tip forgot the moment the page reloaded.

Tips now carry the date they concern, lifted from figures the rules already
computed, so a view of a month can show only what applies to it. They are
built per child and identified per child, so the same rule firing for two
children is two separate pieces of advice.

A dismissal is stored against a fingerprint of the facts that were dismissed.
When those facts change the advice returns with its new numbers, rather than
one click silencing a warning about a forfeiture that keeps growing.
This commit is contained in:
2026-09-17 22:32:03 +02:00
parent c15cd44cb4
commit fdbfb7d580
20 changed files with 1396 additions and 57 deletions
+19 -24
View File
@@ -13,20 +13,14 @@ from uuid import UUID
from fastapi import APIRouter, HTTPException, status
from app.dependencies import (
ChildRepositoryDep,
ChildServiceDep,
CurrentUserDep,
LeaveWishRepositoryDep,
ParentalLeaveRepositoryDep,
PersonalDataRepositoryDep,
PersonalDataServiceDep,
PlannedLeaveRepositoryDep,
VacationDaysRepositoryDep,
WorkspaceRepositoryDep,
TipsServiceDep,
)
from app.models.child import ChildCreate, ChildResponse, ChildUpdate
from app.models.personal_data import PersonalDataResponse, PersonalDataUpdate
from app.services.tips_service import TipsService
from app.models.tips import TipDismissalCreate, TipResponse
from app.utils.errors import NotFoundError, ValidationError
router = APIRouter(tags=["settings"])
@@ -39,26 +33,27 @@ router = APIRouter(tags=["settings"])
tips_router = APIRouter(prefix="/api/tips", tags=["tips"])
@tips_router.get("/{workspace_id}", response_model=list[dict])
@tips_router.get("/{workspace_id}", response_model=list[TipResponse])
async def get_tips(
workspace_id: UUID,
leave_repo: ParentalLeaveRepositoryDep,
planned_repo: PlannedLeaveRepositoryDep,
child_repo: ChildRepositoryDep,
pd_repo: PersonalDataRepositoryDep,
vacation_repo: VacationDaysRepositoryDep,
leave_wish_repo: LeaveWishRepositoryDep,
ws_repo: WorkspaceRepositoryDep,
service: TipsServiceDep,
_current_user: CurrentUserDep,
) -> list[dict]:
service = TipsService(
leave_repo, planned_repo, child_repo, pd_repo, vacation_repo, leave_wish_repo, ws_repo
)
) -> list[TipResponse]:
tips = await service.get_tips(workspace_id)
return [
{"id": t.id, "severity": t.severity, "message_key": t.message_key, "data": t.data}
for t in tips
]
return [TipResponse.from_domain(tip) for tip in tips]
@tips_router.post("/{workspace_id}/dismissals", status_code=status.HTTP_204_NO_CONTENT)
async def dismiss_tip(
workspace_id: UUID,
payload: TipDismissalCreate,
service: TipsServiceDep,
_current_user: CurrentUserDep,
) -> None:
try:
await service.dismiss(workspace_id, payload.tip_id)
except NotFoundError as exc:
raise HTTPException(status.HTTP_404_NOT_FOUND, str(exc)) from exc
# ---------------------------------------------------------------------------