implemented postgres support in repositories
This commit is contained in:
@@ -9,15 +9,15 @@ from baby_monitor.models.sleep import (
|
||||
SleepResponse,
|
||||
)
|
||||
from baby_monitor.routers.auth import verify_token
|
||||
from baby_monitor.repositories.sleep.sqlite_sleep import SQLiteSleepRepository
|
||||
from baby_monitor.repositories.dependencies.get_sleep_repository import (
|
||||
get_sleep_repository,
|
||||
from baby_monitor.repositories.interfaces import (
|
||||
SleepRepositoryInterface,
|
||||
ChildRepositoryInterface,
|
||||
)
|
||||
from baby_monitor.repositories.child.sqlite_child import SQLiteChildRepository
|
||||
from baby_monitor.repositories.dependencies.get_child_repository import (
|
||||
from baby_monitor.repositories.dependencies import (
|
||||
get_sleep_repository,
|
||||
get_child_repository,
|
||||
)
|
||||
from baby_monitor.utils.access_control import verify_child_access
|
||||
from baby_monitor.utils import verify_child_access
|
||||
|
||||
router = APIRouter(prefix="/api/sleep", tags=["sleep"])
|
||||
|
||||
@@ -26,8 +26,12 @@ router = APIRouter(prefix="/api/sleep", tags=["sleep"])
|
||||
def create_sleep(
|
||||
request: CreateSleepRequest,
|
||||
user_id: Annotated[int, Depends(verify_token)],
|
||||
sleep_repo: Annotated[SQLiteSleepRepository, Depends(get_sleep_repository)],
|
||||
child_repo: Annotated[SQLiteChildRepository, Depends(get_child_repository)],
|
||||
sleep_repo: Annotated[
|
||||
SleepRepositoryInterface, Depends(get_sleep_repository)
|
||||
],
|
||||
child_repo: Annotated[
|
||||
ChildRepositoryInterface, Depends(get_child_repository)
|
||||
],
|
||||
) -> SleepResponse:
|
||||
"""Create a new sleep log entry."""
|
||||
# Verify the child belongs to the authenticated user
|
||||
@@ -44,8 +48,12 @@ def create_sleep(
|
||||
@router.get("/active", response_model=SleepResponse | None)
|
||||
def get_active_sleep(
|
||||
user_id: Annotated[int, Depends(verify_token)],
|
||||
sleep_repo: Annotated[SQLiteSleepRepository, Depends(get_sleep_repository)],
|
||||
child_repo: Annotated[SQLiteChildRepository, Depends(get_child_repository)],
|
||||
sleep_repo: Annotated[
|
||||
SleepRepositoryInterface, Depends(get_sleep_repository)
|
||||
],
|
||||
child_repo: Annotated[
|
||||
ChildRepositoryInterface, Depends(get_child_repository)
|
||||
],
|
||||
) -> SleepResponse | None:
|
||||
"""Get the current active sleep (where end_time is null) for the user."""
|
||||
sleeps = sleep_repo.get_by_user_id(user_id)
|
||||
@@ -66,7 +74,9 @@ def get_active_sleep(
|
||||
@router.get("", response_model=list[SleepResponse])
|
||||
def get_user_sleeps(
|
||||
user_id: Annotated[int, Depends(verify_token)],
|
||||
sleep_repo: Annotated[SQLiteSleepRepository, Depends(get_sleep_repository)],
|
||||
sleep_repo: Annotated[
|
||||
SleepRepositoryInterface, Depends(get_sleep_repository)
|
||||
],
|
||||
) -> list[SleepResponse]:
|
||||
"""Get all sleep logs for the authenticated user's children."""
|
||||
sleeps = sleep_repo.get_by_user_id(user_id)
|
||||
@@ -77,8 +87,12 @@ def get_user_sleeps(
|
||||
def get_sleep(
|
||||
sleep_id: int,
|
||||
user_id: Annotated[int, Depends(verify_token)],
|
||||
sleep_repo: Annotated[SQLiteSleepRepository, Depends(get_sleep_repository)],
|
||||
child_repo: Annotated[SQLiteChildRepository, Depends(get_child_repository)],
|
||||
sleep_repo: Annotated[
|
||||
SleepRepositoryInterface, Depends(get_sleep_repository)
|
||||
],
|
||||
child_repo: Annotated[
|
||||
ChildRepositoryInterface, Depends(get_child_repository)
|
||||
],
|
||||
) -> SleepResponse:
|
||||
"""Get a specific sleep log by ID."""
|
||||
sleep = sleep_repo.get_by_id(sleep_id)
|
||||
@@ -97,8 +111,12 @@ def update_sleep(
|
||||
sleep_id: int,
|
||||
request: UpdateSleepRequest,
|
||||
user_id: Annotated[int, Depends(verify_token)],
|
||||
sleep_repo: Annotated[SQLiteSleepRepository, Depends(get_sleep_repository)],
|
||||
child_repo: Annotated[SQLiteChildRepository, Depends(get_child_repository)],
|
||||
sleep_repo: Annotated[
|
||||
SleepRepositoryInterface, Depends(get_sleep_repository)
|
||||
],
|
||||
child_repo: Annotated[
|
||||
ChildRepositoryInterface, Depends(get_child_repository)
|
||||
],
|
||||
) -> SleepResponse:
|
||||
"""Update an existing sleep log."""
|
||||
sleep = sleep_repo.get_by_id(sleep_id)
|
||||
@@ -124,8 +142,12 @@ def update_sleep(
|
||||
def delete_sleep(
|
||||
sleep_id: int,
|
||||
user_id: Annotated[int, Depends(verify_token)],
|
||||
sleep_repo: Annotated[SQLiteSleepRepository, Depends(get_sleep_repository)],
|
||||
child_repo: Annotated[SQLiteChildRepository, Depends(get_child_repository)],
|
||||
sleep_repo: Annotated[
|
||||
SleepRepositoryInterface, Depends(get_sleep_repository)
|
||||
],
|
||||
child_repo: Annotated[
|
||||
ChildRepositoryInterface, Depends(get_child_repository)
|
||||
],
|
||||
) -> None:
|
||||
"""Delete a sleep log."""
|
||||
sleep = sleep_repo.get_by_id(sleep_id)
|
||||
|
||||
Reference in New Issue
Block a user