From 05560d766ad353e7cb7d16308252a712debc8800 Mon Sep 17 00:00:00 2001 From: Brian Bjarke Jensen Date: Wed, 12 Nov 2025 17:01:06 +0100 Subject: [PATCH] added shared parent info and edit child info modal --- src/baby_monitor/models/child.py | 2 + src/baby_monitor/routers/child.py | 29 ++++++- src/baby_monitor/static/settings.html | 110 ++++++++++++++++++++++++-- 3 files changed, 134 insertions(+), 7 deletions(-) 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..d36aa09 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"]) @@ -61,11 +63,34 @@ def create_child( @router.get("", response_model=list[ChildResponse]) def get_user_children( user_id: Annotated[int, Depends(verify_token)], - child_repo: Annotated[ChildRepositoryInterface, Depends(get_child_repository)], + 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/settings.html b/src/baby_monitor/static/settings.html index 9990759..90a03bf 100644 --- a/src/baby_monitor/static/settings.html +++ b/src/baby_monitor/static/settings.html @@ -166,6 +166,16 @@ gap: 10px; } + .shared-badge { + display: inline-block; + background: #4CAF50; + color: white; + padding: 4px 10px; + border-radius: 12px; + font-size: 12px; + font-weight: 500; + } + .loading { text-align: center; padding: 40px; @@ -468,6 +478,65 @@ + + +