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:
@@ -6,6 +6,7 @@ class Child(BaseModel):
|
||||
name: str
|
||||
age: int | None = None
|
||||
tasks: list[str] = field(default_factory=list)
|
||||
routines: list[str] = field(default_factory=list)
|
||||
rewards: list[str] = field(default_factory=list)
|
||||
points: int = 0
|
||||
image_id: str | None = None
|
||||
@@ -17,6 +18,7 @@ class Child(BaseModel):
|
||||
name=d.get('name'),
|
||||
age=d.get('age'),
|
||||
tasks=d.get('tasks', []),
|
||||
routines=d.get('routines', []),
|
||||
rewards=d.get('rewards', []),
|
||||
points=d.get('points', 0),
|
||||
image_id=d.get('image_id'),
|
||||
@@ -32,6 +34,7 @@ class Child(BaseModel):
|
||||
'name': self.name,
|
||||
'age': self.age,
|
||||
'tasks': self.tasks,
|
||||
'routines': self.routines,
|
||||
'rewards': self.rewards,
|
||||
'points': self.points,
|
||||
'image_id': self.image_id,
|
||||
|
||||
@@ -16,15 +16,15 @@ class ChildOverride(BaseModel):
|
||||
"""
|
||||
child_id: str
|
||||
entity_id: str
|
||||
entity_type: Literal['task', 'reward', 'chore', 'kindness', 'penalty']
|
||||
entity_type: Literal['task', 'reward', 'chore', 'kindness', 'penalty', 'routine']
|
||||
custom_value: int
|
||||
|
||||
def __post_init__(self):
|
||||
"""Validate custom_value range and entity_type."""
|
||||
if self.custom_value < 0 or self.custom_value > 10000:
|
||||
raise ValueError("custom_value must be between 0 and 10000")
|
||||
if self.entity_type not in ['task', 'reward', 'chore', 'kindness', 'penalty']:
|
||||
raise ValueError("entity_type must be 'task', 'reward', 'chore', 'kindness', or 'penalty'")
|
||||
if self.entity_type not in ['task', 'reward', 'chore', 'kindness', 'penalty', 'routine']:
|
||||
raise ValueError("entity_type must be 'task', 'reward', 'chore', 'kindness', 'penalty', or 'routine'")
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, d: dict):
|
||||
@@ -52,7 +52,7 @@ class ChildOverride(BaseModel):
|
||||
def create_override(
|
||||
child_id: str,
|
||||
entity_id: str,
|
||||
entity_type: Literal['task', 'reward', 'chore', 'kindness', 'penalty'],
|
||||
entity_type: Literal['task', 'reward', 'chore', 'kindness', 'penalty', 'routine'],
|
||||
custom_value: int
|
||||
) -> 'ChildOverride':
|
||||
"""Factory method to create a new override."""
|
||||
|
||||
@@ -3,7 +3,7 @@ from typing import Literal, Optional
|
||||
from models.base import BaseModel
|
||||
|
||||
|
||||
PendingEntityType = Literal['chore', 'reward']
|
||||
PendingEntityType = Literal['chore', 'reward', 'routine']
|
||||
PendingStatus = Literal['pending', 'approved', 'rejected']
|
||||
|
||||
|
||||
|
||||
32
backend/models/routine.py
Normal file
32
backend/models/routine.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from dataclasses import dataclass
|
||||
from models.base import BaseModel
|
||||
|
||||
|
||||
@dataclass
|
||||
class Routine(BaseModel):
|
||||
name: str
|
||||
points: int
|
||||
image_id: str | None = None
|
||||
user_id: str | None = None
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, d: dict):
|
||||
return cls(
|
||||
name=d.get('name'),
|
||||
points=d.get('points', 0),
|
||||
image_id=d.get('image_id'),
|
||||
user_id=d.get('user_id'),
|
||||
id=d.get('id'),
|
||||
created_at=d.get('created_at'),
|
||||
updated_at=d.get('updated_at')
|
||||
)
|
||||
|
||||
def to_dict(self):
|
||||
base = super().to_dict()
|
||||
base.update({
|
||||
'name': self.name,
|
||||
'points': self.points,
|
||||
'image_id': self.image_id,
|
||||
'user_id': self.user_id
|
||||
})
|
||||
return base
|
||||
29
backend/models/routine_extension.py
Normal file
29
backend/models/routine_extension.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from dataclasses import dataclass
|
||||
from models.base import BaseModel
|
||||
|
||||
|
||||
@dataclass
|
||||
class RoutineExtension(BaseModel):
|
||||
child_id: str
|
||||
routine_id: str
|
||||
date: str
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, d: dict) -> 'RoutineExtension':
|
||||
return cls(
|
||||
child_id=d.get('child_id'),
|
||||
routine_id=d.get('routine_id'),
|
||||
date=d.get('date'),
|
||||
id=d.get('id'),
|
||||
created_at=d.get('created_at'),
|
||||
updated_at=d.get('updated_at'),
|
||||
)
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
base = super().to_dict()
|
||||
base.update({
|
||||
'child_id': self.child_id,
|
||||
'routine_id': self.routine_id,
|
||||
'date': self.date,
|
||||
})
|
||||
return base
|
||||
32
backend/models/routine_item.py
Normal file
32
backend/models/routine_item.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from dataclasses import dataclass
|
||||
from models.base import BaseModel
|
||||
|
||||
|
||||
@dataclass
|
||||
class RoutineItem(BaseModel):
|
||||
routine_id: str
|
||||
name: str
|
||||
image_id: str | None = None
|
||||
order: int = 0
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, d: dict):
|
||||
return cls(
|
||||
routine_id=d.get('routine_id'),
|
||||
name=d.get('name'),
|
||||
image_id=d.get('image_id'),
|
||||
order=d.get('order', 0),
|
||||
id=d.get('id'),
|
||||
created_at=d.get('created_at'),
|
||||
updated_at=d.get('updated_at')
|
||||
)
|
||||
|
||||
def to_dict(self):
|
||||
base = super().to_dict()
|
||||
base.update({
|
||||
'routine_id': self.routine_id,
|
||||
'name': self.name,
|
||||
'image_id': self.image_id,
|
||||
'order': self.order
|
||||
})
|
||||
return base
|
||||
63
backend/models/routine_schedule.py
Normal file
63
backend/models/routine_schedule.py
Normal file
@@ -0,0 +1,63 @@
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Literal
|
||||
from models.base import BaseModel
|
||||
|
||||
|
||||
@dataclass
|
||||
class RoutineSchedule(BaseModel):
|
||||
child_id: str
|
||||
routine_id: str
|
||||
mode: Literal['days', 'interval']
|
||||
|
||||
day_configs: list = field(default_factory=list)
|
||||
default_hour: int = 8
|
||||
default_minute: int = 0
|
||||
default_has_deadline: bool = True
|
||||
|
||||
interval_days: int = 2
|
||||
anchor_date: str = ""
|
||||
interval_has_deadline: bool = True
|
||||
interval_hour: int = 0
|
||||
interval_minute: int = 0
|
||||
|
||||
enabled: bool = True
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, d: dict) -> 'RoutineSchedule':
|
||||
return cls(
|
||||
child_id=d.get('child_id'),
|
||||
routine_id=d.get('routine_id'),
|
||||
mode=d.get('mode', 'days'),
|
||||
day_configs=d.get('day_configs', []),
|
||||
default_hour=d.get('default_hour', 8),
|
||||
default_minute=d.get('default_minute', 0),
|
||||
default_has_deadline=d.get('default_has_deadline', True),
|
||||
interval_days=d.get('interval_days', 2),
|
||||
anchor_date=d.get('anchor_date', ''),
|
||||
interval_has_deadline=d.get('interval_has_deadline', True),
|
||||
interval_hour=d.get('interval_hour', 0),
|
||||
interval_minute=d.get('interval_minute', 0),
|
||||
enabled=d.get('enabled', True),
|
||||
id=d.get('id'),
|
||||
created_at=d.get('created_at'),
|
||||
updated_at=d.get('updated_at'),
|
||||
)
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
base = super().to_dict()
|
||||
base.update({
|
||||
'child_id': self.child_id,
|
||||
'routine_id': self.routine_id,
|
||||
'mode': self.mode,
|
||||
'day_configs': self.day_configs,
|
||||
'default_hour': self.default_hour,
|
||||
'default_minute': self.default_minute,
|
||||
'default_has_deadline': self.default_has_deadline,
|
||||
'interval_days': self.interval_days,
|
||||
'anchor_date': self.anchor_date,
|
||||
'interval_has_deadline': self.interval_has_deadline,
|
||||
'interval_hour': self.interval_hour,
|
||||
'interval_minute': self.interval_minute,
|
||||
'enabled': self.enabled,
|
||||
})
|
||||
return base
|
||||
Reference in New Issue
Block a user