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.
40 lines
1.0 KiB
Python
40 lines
1.0 KiB
Python
from tinydb import Query
|
|
from db.db import routine_db
|
|
from models.routine import Routine
|
|
|
|
|
|
def add_routine(routine: Routine) -> None:
|
|
routine_db.insert(routine.to_dict())
|
|
|
|
|
|
def get_routine(routine_id: str) -> Routine | None:
|
|
q = Query()
|
|
result = routine_db.search(q.id == routine_id)
|
|
if not result:
|
|
return None
|
|
return Routine.from_dict(result[0])
|
|
|
|
|
|
def update_routine(routine: Routine) -> bool:
|
|
q = Query()
|
|
existing = routine_db.get(q.id == routine.id)
|
|
if not existing:
|
|
return False
|
|
routine_db.update(routine.to_dict(), q.id == routine.id)
|
|
return True
|
|
|
|
|
|
def delete_routine(routine_id: str) -> bool:
|
|
q = Query()
|
|
existing = routine_db.get(q.id == routine_id)
|
|
if not existing:
|
|
return False
|
|
routine_db.remove(q.id == routine_id)
|
|
return True
|
|
|
|
|
|
def list_routines_for_user(user_id: str) -> list[Routine]:
|
|
q = Query()
|
|
results = routine_db.search((q.user_id == user_id) | (q.user_id == None))
|
|
return [Routine.from_dict(r) for r in results]
|