diff --git a/src/baby_monitor/models/child.py b/src/baby_monitor/models/child.py index 17ab949..d3858a2 100644 --- a/src/baby_monitor/models/child.py +++ b/src/baby_monitor/models/child.py @@ -20,3 +20,5 @@ class ChildResponse(BaseModel): birth_time: datetime birth_weight: float created_at: datetime + parent_count: int | None = None + parent_usernames: list[str] | None = None diff --git a/src/baby_monitor/routers/child.py b/src/baby_monitor/routers/child.py index 456e78b..fc628d3 100644 --- a/src/baby_monitor/routers/child.py +++ b/src/baby_monitor/routers/child.py @@ -11,10 +11,12 @@ from baby_monitor.routers.auth import verify_token from baby_monitor.repositories.interfaces import ( ChildRepositoryInterface, ChildInvitationRepositoryInterface, + UserRepositoryInterface, ) from baby_monitor.repositories.dependencies import ( get_child_repository, get_child_invitation_repository, + get_user_repository, ) router = APIRouter(prefix="/api/children", tags=["children"]) @@ -62,10 +64,29 @@ def create_child( def get_user_children( user_id: Annotated[int, Depends(verify_token)], child_repo: Annotated[ChildRepositoryInterface, Depends(get_child_repository)], + user_repo: Annotated[UserRepositoryInterface, Depends(get_user_repository)], ) -> list[ChildResponse]: """Get all children for the authenticated user.""" children = child_repo.get_by_user_id(user_id) - return [ChildResponse(**child) for child in children] + + # Add parent information to each child + result = [] + for child in children: + child_data = child.copy() + parent_ids = child_repo.get_parent_ids(child["id"]) + child_data["parent_count"] = len(parent_ids) + + # Get usernames of all parents + parent_usernames = [] + for parent_id in parent_ids: + parent = user_repo.get_by_id(parent_id) + if parent: + parent_usernames.append(parent["username"]) + child_data["parent_usernames"] = parent_usernames + + result.append(ChildResponse(**child_data)) + + return result @router.get("/{child_id}", response_model=ChildResponse) diff --git a/src/baby_monitor/static/diapers.html b/src/baby_monitor/static/diapers.html index 6bf330d..b02239c 100644 --- a/src/baby_monitor/static/diapers.html +++ b/src/baby_monitor/static/diapers.html @@ -321,7 +321,7 @@ if (response.ok) { allChildren = await response.json(); - + // Auto-select first child if no selection exists if (selectedChildId === null && allChildren.length > 0) { selectedChildId = allChildren[0].id; @@ -371,7 +371,9 @@ content.innerHTML = `
- ${allChildren.length === 1 ? ` + ${ + allChildren.length === 1 + ? ` - ` : ` + ` + : ` - `} + ` + } - ` : ` + ` + : ` - `} + ` + }