-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevents.py
54 lines (43 loc) · 1.36 KB
/
events.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
import datetime
import uuid
from dataclasses import dataclass
from typing import Protocol
from google.protobuf.message import Message as ProtoMessage
from adapters import proto
class Event(Protocol):
event_id: uuid.UUID
correlation_id: uuid.UUID
order_id: uuid.UUID
created_at: datetime.datetime
def to_proto(self) -> ProtoMessage:
...
@dataclass
class CustomerCreatedEvent:
event_id: uuid.UUID
correlation_id: uuid.UUID
customer_id: uuid.UUID
name: str
created_at: datetime.datetime
def to_proto(self) -> proto.CustomerCreated:
return proto.CustomerCreated(
event_id=str(self.event_id),
correlation_id=str(self.correlation_id),
customer_id=str(self.customer_id),
name=self.name,
created_at=self.created_at.isoformat(),
)
@dataclass
class CustomerCreditReservedEvent:
event_id: uuid.UUID
correlation_id: uuid.UUID
order_id: uuid.UUID
customer_id: uuid.UUID
created_at: datetime.datetime
def to_proto(self) -> proto.CustomerCreditReserved:
return proto.CustomerCreditReserved(
event_id=str(self.event_id),
correlation_id=str(self.correlation_id),
customer_id=str(self.customer_id),
order_id=str(self.order_id),
created_at=self.created_at.isoformat(),
)