feat: Implement routines feature with CRUD operations and child assignment
All checks were successful
Chore App Build, Test, and Push Docker Images / build-and-push (push) Successful in 3m0s
All checks were successful
Chore App Build, Test, and Push Docker Images / build-and-push (push) Successful in 3m0s
- Add backend routines management with add, get, update, delete, and list functionalities. - Create models for Routine, RoutineItem, RoutineSchedule, and RoutineExtension. - Develop event types for routine confirmation and modification. - Implement frontend components for routine assignment, confirmation dialog, and routine management views. - Add unit tests for routine API and integration tests for routine CRUD flow. - Create end-to-end test plan for routines feature covering parent and child interactions.
This commit is contained in:
42
backend/db/routine_schedules.py
Normal file
42
backend/db/routine_schedules.py
Normal file
@@ -0,0 +1,42 @@
|
||||
from tinydb import Query
|
||||
from db.db import routine_schedules_db
|
||||
from models.routine_schedule import RoutineSchedule
|
||||
|
||||
|
||||
def get_schedule(child_id: str, routine_id: str) -> RoutineSchedule | None:
|
||||
q = Query()
|
||||
result = routine_schedules_db.search((q.child_id == child_id) & (q.routine_id == routine_id))
|
||||
if not result:
|
||||
return None
|
||||
return RoutineSchedule.from_dict(result[0])
|
||||
|
||||
|
||||
def upsert_schedule(schedule: RoutineSchedule) -> None:
|
||||
q = Query()
|
||||
existing = routine_schedules_db.get((q.child_id == schedule.child_id) & (q.routine_id == schedule.routine_id))
|
||||
if existing:
|
||||
routine_schedules_db.update(
|
||||
schedule.to_dict(),
|
||||
(q.child_id == schedule.child_id) & (q.routine_id == schedule.routine_id)
|
||||
)
|
||||
else:
|
||||
routine_schedules_db.insert(schedule.to_dict())
|
||||
|
||||
|
||||
def delete_schedule(child_id: str, routine_id: str) -> bool:
|
||||
q = Query()
|
||||
existing = routine_schedules_db.get((q.child_id == child_id) & (q.routine_id == routine_id))
|
||||
if not existing:
|
||||
return False
|
||||
routine_schedules_db.remove((q.child_id == child_id) & (q.routine_id == routine_id))
|
||||
return True
|
||||
|
||||
|
||||
def delete_schedules_for_child(child_id: str) -> None:
|
||||
q = Query()
|
||||
routine_schedules_db.remove(q.child_id == child_id)
|
||||
|
||||
|
||||
def delete_schedules_for_routine(routine_id: str) -> None:
|
||||
q = Query()
|
||||
routine_schedules_db.remove(q.routine_id == routine_id)
|
||||
Reference in New Issue
Block a user