34 lines
869 B
Python
34 lines
869 B
Python
# python
|
|
from dataclasses import dataclass
|
|
from models.base import BaseModel
|
|
|
|
@dataclass
|
|
class Reward(BaseModel):
|
|
name: str
|
|
description: str
|
|
cost: int
|
|
image_id: str | None = None
|
|
|
|
@classmethod
|
|
def from_dict(cls, d: dict):
|
|
# Base fields are keyword-only; can be overridden if provided
|
|
return cls(
|
|
name=d.get('name'),
|
|
description=d.get('description'),
|
|
cost=d.get('cost', 0),
|
|
image_id=d.get('image_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,
|
|
'description': self.description,
|
|
'cost': self.cost,
|
|
'image_id': self.image_id
|
|
})
|
|
return base
|