34 lines
761 B
Python
34 lines
761 B
Python
from dataclasses import dataclass
|
|
import uuid
|
|
|
|
@dataclass
|
|
class Reward:
|
|
name: str
|
|
description: str
|
|
cost: int
|
|
image_id: str | None = None
|
|
id: str | None = None
|
|
|
|
def __post_init__(self):
|
|
if self.id is None:
|
|
self.id = str(uuid.uuid4())
|
|
|
|
@classmethod
|
|
def from_dict(cls, d: dict):
|
|
return cls(
|
|
id=d.get('id'),
|
|
name=d.get('name'),
|
|
description=d.get('description'),
|
|
cost=d.get('cost', 0),
|
|
image_id=d.get('image_id')
|
|
)
|
|
|
|
def to_dict(self):
|
|
return {
|
|
'id': self.id,
|
|
'name': self.name,
|
|
'description': self.description,
|
|
'cost': self.cost,
|
|
'image_id': self.image_id
|
|
}
|