-
Notifications
You must be signed in to change notification settings - Fork 0
/
handlers.go
43 lines (35 loc) · 1.11 KB
/
handlers.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 events
import (
"errors"
"github.com/HETIC-MT-P2021/CQRSES_GROUP4/event"
)
// ArticleCreatedEventHandler allows to create an article
type ArticleCreatedEventHandler struct{}
// Handle Creates a new article
func (eHandler ArticleCreatedEventHandler) Handle(ev event.Event) error {
switch evType := ev.Type(); evType {
case ArticleCreatedEventType:
return ArticleCreatedEvent{}.Apply(ev)
default:
return errors.New("bad event")
}
}
// NewArticleCreatedEventHandler Creates an instance
func NewArticleCreatedEventHandler() *ArticleCreatedEventHandler {
return &ArticleCreatedEventHandler{}
}
// ArticleUpdatedEventHandler allows to update an article
type ArticleUpdatedEventHandler struct{}
// Handle Updates a new article
func (eHandler ArticleUpdatedEventHandler) Handle(ev event.Event) error {
switch evType := ev.Type(); evType {
case ArticleUpdatedEventType:
return ArticleUpdatedEvent{}.Apply(ev)
default:
return errors.New("bad event")
}
}
// NewArticleUpdatedEventHandler Creates an instance
func NewArticleUpdatedEventHandler() *ArticleUpdatedEventHandler {
return &ArticleUpdatedEventHandler{}
}