-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase_event.go
More file actions
56 lines (48 loc) · 1.52 KB
/
base_event.go
File metadata and controls
56 lines (48 loc) · 1.52 KB
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
55
56
package domain
import (
"context"
"time"
)
type MongoEvent interface {
Type() string
}
type EventService[T AggregateRoot[U], U ~string] interface {
Append(ctx context.Context, options AppendOptions, events ...AppendEvent[U]) error
GetByID(ctx context.Context, id U) (t T, version Version, err error)
GetByIDAndName(ctx context.Context, id U, name AggregateName) (t T, version Version, err error)
}
type AggregateRoot[U ~string] interface {
ID() U
Apply(any) // The method to project an Event onto the Aggregate
}
type AppendOptions struct {
RequestID RequestID // The ID of the Request, used for idempotency
CorrelationID CorrelationID // The ID of the entire Command and Event chain
UserID UserID // The ID of the User issuing the Command
Time time.Time // The Time this Event was created
}
type AppendEvent[U ~string] struct {
EventID EventID // The ID of the Event, use for de-duplication
AggregateID U // The ID of the Aggregate to which this Event applies
Version Version // The Version of the Aggregate
PartitionID PartitionID // The ID to partition Events
Data BaseEvent // The Data for the Event
}
type BaseEvent interface {
AggregateName() string
EventName() string
Schema() string
}
func NewAppendEvent[U ~string](
aggregateID U,
version Version,
partitionID PartitionID,
data BaseEvent,
) AppendEvent[U] {
return AppendEvent[U]{
AggregateID: aggregateID,
Version: version + 1,
PartitionID: partitionID,
Data: data,
}
}