-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathroom_aggregate_gen.go
125 lines (91 loc) · 2.36 KB
/
room_aggregate_gen.go
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Code generated by go generate; DO NOT EDIT.
// This file was generated at
// 2021-11-19 15:31:40.053991 -0800 PST m=+0.001858260
package chat
import (
"github.com/inklabs/rangedb"
"github.com/inklabs/rangedb/pkg/cqrs"
)
func (a *room) Load(recordIterator rangedb.RecordIterator) {
for recordIterator.Next() {
if recordIterator.Err() == nil {
if event, ok := recordIterator.Record().Data.(rangedb.Event); ok {
a.apply(event)
}
}
}
}
func (a *room) apply(event rangedb.Event) {
switch e := event.(type) {
case RoomWasOnBoarded:
a.roomWasOnBoarded(e)
case *RoomWasOnBoarded:
a.roomWasOnBoarded(*e)
case RoomWasJoined:
a.roomWasJoined(e)
case *RoomWasJoined:
a.roomWasJoined(*e)
case MessageWasSentToRoom:
a.messageWasSentToRoom(e)
case *MessageWasSentToRoom:
a.messageWasSentToRoom(*e)
case PrivateMessageWasSentToRoom:
a.privateMessageWasSentToRoom(e)
case *PrivateMessageWasSentToRoom:
a.privateMessageWasSentToRoom(*e)
case UserWasRemovedFromRoom:
a.userWasRemovedFromRoom(e)
case *UserWasRemovedFromRoom:
a.userWasRemovedFromRoom(*e)
case UserWasBannedFromRoom:
a.userWasBannedFromRoom(e)
case *UserWasBannedFromRoom:
a.userWasBannedFromRoom(*e)
}
}
func (a *room) Handle(command cqrs.Command) []rangedb.Event {
switch c := command.(type) {
case OnBoardRoom:
a.onBoardRoom(c)
case *OnBoardRoom:
a.onBoardRoom(*c)
case JoinRoom:
a.joinRoom(c)
case *JoinRoom:
a.joinRoom(*c)
case SendMessageToRoom:
a.sendMessageToRoom(c)
case *SendMessageToRoom:
a.sendMessageToRoom(*c)
case SendPrivateMessageToRoom:
a.sendPrivateMessageToRoom(c)
case *SendPrivateMessageToRoom:
a.sendPrivateMessageToRoom(*c)
case RemoveUserFromRoom:
a.removeUserFromRoom(c)
case *RemoveUserFromRoom:
a.removeUserFromRoom(*c)
case BanUserFromRoom:
a.banUserFromRoom(c)
case *BanUserFromRoom:
a.banUserFromRoom(*c)
}
defer a.resetPendingEvents()
return a.pendingEvents
}
func (a *room) resetPendingEvents() {
a.pendingEvents = nil
}
func (a *room) CommandTypes() []string {
return []string{
OnBoardRoom{}.CommandType(),
JoinRoom{}.CommandType(),
SendMessageToRoom{}.CommandType(),
SendPrivateMessageToRoom{}.CommandType(),
RemoveUserFromRoom{}.CommandType(),
BanUserFromRoom{}.CommandType(),
}
}
func (a *room) raise(events ...rangedb.Event) {
a.pendingEvents = append(a.pendingEvents, events...)
}