-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathemitter.go
43 lines (32 loc) · 1.26 KB
/
emitter.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
package user
import (
"context"
"github.com/ThreeDotsLabs/watermill/components/cqrs"
)
type Emitter struct {
bus *cqrs.EventBus
}
func NewEmitter(bus *cqrs.EventBus) Emitter {
return Emitter{bus: bus}
}
func (emitter Emitter) UserCreated(ctx context.Context, user User) error {
return emitter.bus.Publish(ctx, UserCreated{User: user})
}
func (emitter Emitter) FailedToCreateUser(ctx context.Context, err error) error {
return emitter.bus.Publish(ctx, FailedToCreateUser{Error: err.Error()})
}
func (emitter Emitter) FailedToDeleteAll(ctx context.Context, err error) error {
return emitter.bus.Publish(ctx, FailedToDeleteAll{Error: err.Error()})
}
func (emitter Emitter) FailedToFindByID(ctx context.Context, err error) error {
return emitter.bus.Publish(ctx, FailedToFindByID{Error: err.Error()})
}
func (emitter Emitter) FailedToFindByName(ctx context.Context, err error) error {
return emitter.bus.Publish(ctx, FailedToFindByName{Error: err.Error()})
}
func (emitter Emitter) FailedToRemoveUser(ctx context.Context, err error, user User) error {
return emitter.bus.Publish(ctx, FailedToRemoveUser{Error: err.Error(), User: user})
}
func (emitter Emitter) UserRemoved(ctx context.Context, user User) any {
return emitter.bus.Publish(ctx, UserRemoved{User: user})
}