Files
chore/backend/models/child.py
Ryan Kegel f14de28daa
All checks were successful
Gitea Actions Demo / build-and-push (push) Successful in 36s
feat: Implement user validation and ownership checks for image, reward, and task APIs
- Added `get_validated_user_id` utility function to validate user authentication across multiple APIs.
- Updated image upload, request, and listing endpoints to ensure user ownership and proper error handling.
- Enhanced reward management endpoints to include user validation and ownership checks.
- Modified task management endpoints to enforce user authentication and ownership verification.
- Updated models to include `user_id` for images, rewards, tasks, and children to track ownership.
- Implemented frontend changes to ensure UI reflects the ownership of tasks and rewards.
- Added a new feature specification to prevent deletion of system tasks and rewards.
2026-01-31 19:48:51 -05:00

41 lines
1.1 KiB
Python

from dataclasses import dataclass, field
from models.base import BaseModel
@dataclass
class Child(BaseModel):
name: str
age: int | None = None
tasks: list[str] = field(default_factory=list)
rewards: list[str] = field(default_factory=list)
points: int = 0
image_id: str | None = None
user_id: str | None = None
@classmethod
def from_dict(cls, d: dict):
return cls(
name=d.get('name'),
age=d.get('age'),
tasks=d.get('tasks', []),
rewards=d.get('rewards', []),
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,
'age': self.age,
'tasks': self.tasks,
'rewards': self.rewards,
'points': self.points,
'image_id': self.image_id,
'user_id': self.user_id
})
return base