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.
65 lines
2.2 KiB
Python
65 lines
2.2 KiB
Python
from dataclasses import dataclass
|
|
from typing import Literal
|
|
from models.base import BaseModel
|
|
|
|
|
|
@dataclass
|
|
class ChildOverride(BaseModel):
|
|
"""
|
|
Stores per-child customized points/cost for tasks, penalties, and rewards.
|
|
|
|
Attributes:
|
|
child_id: ID of the child this override applies to
|
|
entity_id: ID of the task/penalty/reward being customized
|
|
entity_type: Type of entity ('task' or 'reward')
|
|
custom_value: Custom points (for tasks/penalties) or cost (for rewards)
|
|
"""
|
|
child_id: str
|
|
entity_id: str
|
|
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', 'routine']:
|
|
raise ValueError("entity_type must be 'task', 'reward', 'chore', 'kindness', 'penalty', or 'routine'")
|
|
|
|
@classmethod
|
|
def from_dict(cls, d: dict):
|
|
return cls(
|
|
child_id=d.get('child_id'),
|
|
entity_id=d.get('entity_id'),
|
|
entity_type=d.get('entity_type'),
|
|
custom_value=d.get('custom_value'),
|
|
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({
|
|
'child_id': self.child_id,
|
|
'entity_id': self.entity_id,
|
|
'entity_type': self.entity_type,
|
|
'custom_value': self.custom_value
|
|
})
|
|
return base
|
|
|
|
@staticmethod
|
|
def create_override(
|
|
child_id: str,
|
|
entity_id: str,
|
|
entity_type: Literal['task', 'reward', 'chore', 'kindness', 'penalty', 'routine'],
|
|
custom_value: int
|
|
) -> 'ChildOverride':
|
|
"""Factory method to create a new override."""
|
|
return ChildOverride(
|
|
child_id=child_id,
|
|
entity_id=entity_id,
|
|
entity_type=entity_type,
|
|
custom_value=custom_value
|
|
)
|