-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmodels.py
More file actions
41 lines (32 loc) · 958 Bytes
/
models.py
File metadata and controls
41 lines (32 loc) · 958 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from __future__ import annotations
from dataclasses import asdict, dataclass, field
from datetime import datetime, timezone
from typing import Any
def _now_iso() -> str:
return datetime.now(timezone.utc).isoformat()
@dataclass(frozen=True)
class DeliveryMessage:
user_id: str
channel: str
title: str
body: str
created_at: str = ""
metadata: dict[str, Any] = field(default_factory=dict)
def to_record(self) -> dict[str, Any]:
row = asdict(self)
row["created_at"] = str(self.created_at or _now_iso())
return row
@dataclass(frozen=True)
class DeliveryReceipt:
delivery_id: str
user_id: str
channel: str
status: str
title: str
body: str
created_at: str = ""
metadata: dict[str, Any] = field(default_factory=dict)
def to_record(self) -> dict[str, Any]:
row = asdict(self)
row["created_at"] = str(self.created_at or _now_iso())
return row