|
from dataclasses import dataclass |
|
from typing import Optional |
|
from datetime import datetime |
|
|
|
@dataclass |
|
class Schedule: |
|
"""Schedule model representing a post scheduling configuration.""" |
|
id: str |
|
social_account_id: str |
|
schedule_time: str |
|
adjusted_time: str |
|
created_at: Optional[datetime] = None |
|
|
|
@classmethod |
|
def from_dict(cls, data: dict): |
|
"""Create a Schedule instance from a dictionary.""" |
|
return cls( |
|
id=data['id'], |
|
social_account_id=data['social_account_id'], |
|
schedule_time=data['schedule_time'], |
|
adjusted_time=data['adjusted_time'], |
|
created_at=datetime.fromisoformat(data['created_at'].replace('Z', '+00:00')) if data.get('created_at') else None |
|
) |
|
|
|
def to_dict(self): |
|
"""Convert Schedule instance to dictionary.""" |
|
return { |
|
'id': self.id, |
|
'social_account_id': self.social_account_id, |
|
'schedule_time': self.schedule_time, |
|
'adjusted_time': self.adjusted_time, |
|
'created_at': self.created_at.isoformat() if self.created_at else None |
|
} |