updated admin page with more functionality, simplified burger menu and added many-to-many parent-child relationship
This commit is contained in:
@@ -19,6 +19,7 @@ from baby_monitor.repositories.child.sqlite_child import SQLiteChildRepository
|
||||
from baby_monitor.repositories.dependencies.get_child_repository import (
|
||||
get_child_repository,
|
||||
)
|
||||
from baby_monitor.utils.access_control import verify_child_access
|
||||
|
||||
router = APIRouter(prefix="/api/feedings", tags=["feedings"])
|
||||
|
||||
@@ -32,12 +33,7 @@ def create_feeding(
|
||||
) -> FeedingResponse:
|
||||
"""Create a new feeding log entry."""
|
||||
# Verify the child belongs to the authenticated user
|
||||
child = child_repo.get_by_id(request.child_id)
|
||||
if not child:
|
||||
raise HTTPException(status_code=404, detail="Child not found")
|
||||
|
||||
if child["user_id"] != user_id:
|
||||
raise HTTPException(status_code=403, detail="Access denied to this child")
|
||||
verify_child_access(child_repo, request.child_id, user_id)
|
||||
|
||||
feeding = feeding_repo.create(
|
||||
child_id=request.child_id,
|
||||
@@ -95,9 +91,7 @@ def get_feeding(
|
||||
raise HTTPException(status_code=404, detail="Feeding log not found")
|
||||
|
||||
# Verify the feeding belongs to user's child
|
||||
child = child_repo.get_by_id(feeding["child_id"])
|
||||
if not child or child["user_id"] != user_id:
|
||||
raise HTTPException(status_code=403, detail="Access denied")
|
||||
verify_child_access(child_repo, feeding["child_id"], user_id)
|
||||
|
||||
return FeedingResponse(**feeding)
|
||||
|
||||
@@ -117,9 +111,7 @@ def update_feeding(
|
||||
raise HTTPException(status_code=404, detail="Feeding log not found")
|
||||
|
||||
# Verify ownership
|
||||
child = child_repo.get_by_id(feeding["child_id"])
|
||||
if not child or child["user_id"] != user_id:
|
||||
raise HTTPException(status_code=403, detail="Access denied")
|
||||
verify_child_access(child_repo, feeding["child_id"], user_id)
|
||||
|
||||
# Update the feeding
|
||||
updated_feeding = feeding_repo.update(
|
||||
@@ -149,9 +141,7 @@ def delete_feeding(
|
||||
raise HTTPException(status_code=404, detail="Feeding log not found")
|
||||
|
||||
# Verify ownership
|
||||
child = child_repo.get_by_id(feeding["child_id"])
|
||||
if not child or child["user_id"] != user_id:
|
||||
raise HTTPException(status_code=403, detail="Access denied")
|
||||
verify_child_access(child_repo, feeding["child_id"], user_id)
|
||||
|
||||
success = feeding_repo.delete(feeding_id)
|
||||
if not success:
|
||||
|
||||
Reference in New Issue
Block a user