-
Notifications
You must be signed in to change notification settings - Fork 0
/
LibraryEventsBase.go
161 lines (127 loc) · 3.87 KB
/
LibraryEventsBase.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package library
import (
"github.com/go-ee/schkola/person"
"encoding/json"
"fmt"
"github.com/go-ee/utils/enum"
"github.com/google/uuid"
"github.com/looplab/eventhorizon"
"gopkg.in/mgo.v2/bson"
"time"
)
const (
BookCreatedEvent eventhorizon.EventType = "BookCreated"
BookDeletedEvent eventhorizon.EventType = "BookDeleted"
BookUpdatedEvent eventhorizon.EventType = "BookUpdated"
)
type BookCreated struct {
Title string `json:"title" eh:"optional"`
Description string `json:"description" eh:"optional"`
Language string `json:"language" eh:"optional"`
ReleaseDate *time.Time `json:"releaseDate" eh:"optional"`
Edition string `json:"edition" eh:"optional"`
Category string `json:"category" eh:"optional"`
Author *person.PersonName `json:"author" eh:"optional"`
Location *Location `json:"location" eh:"optional"`
Id uuid.UUID `json:"id" eh:"optional"`
}
type BookDeleted struct {
Id uuid.UUID `json:"id" eh:"optional"`
}
type BookUpdated struct {
Title string `json:"title" eh:"optional"`
Description string `json:"description" eh:"optional"`
Language string `json:"language" eh:"optional"`
ReleaseDate *time.Time `json:"releaseDate" eh:"optional"`
Edition string `json:"edition" eh:"optional"`
Category string `json:"category" eh:"optional"`
Author *person.PersonName `json:"author" eh:"optional"`
Location *Location `json:"location" eh:"optional"`
Id uuid.UUID `json:"id" eh:"optional"`
}
type BookEventType struct {
name string
ordinal int
}
func (o *BookEventType) Name() string {
return o.name
}
func (o *BookEventType) Ordinal() int {
return o.ordinal
}
func (o BookEventType) MarshalJSON() (ret []byte, err error) {
return json.Marshal(&enum.EnumBaseJson{Name: o.name})
}
func (o *BookEventType) UnmarshalJSON(data []byte) (err error) {
lit := enum.EnumBaseJson{}
if err = json.Unmarshal(data, &lit); err == nil {
if v, ok := BookEventTypes().ParseBookEventType(lit.Name); ok {
*o = *v
} else {
err = fmt.Errorf("invalid BookEventType %q", lit.Name)
}
}
return
}
func (o BookEventType) GetBSON() (ret interface{}, err error) {
return o.name, nil
}
func (o *BookEventType) SetBSON(raw bson.Raw) (err error) {
var lit string
if err = raw.Unmarshal(&lit); err == nil {
if v, ok := BookEventTypes().ParseBookEventType(lit); ok {
*o = *v
} else {
err = fmt.Errorf("invalid BookEventType %q", lit)
}
}
return
}
func (o *BookEventType) IsBookCreated() bool {
return o == _bookEventTypes.BookCreated()
}
func (o *BookEventType) IsBookDeleted() bool {
return o == _bookEventTypes.BookDeleted()
}
func (o *BookEventType) IsBookUpdated() bool {
return o == _bookEventTypes.BookUpdated()
}
type bookEventTypes struct {
values []*BookEventType
literals []enum.Literal
}
var _bookEventTypes = &bookEventTypes{values: []*BookEventType{
{name: "BookCreated", ordinal: 0},
{name: "BookDeleted", ordinal: 1},
{name: "BookUpdated", ordinal: 2}},
}
func BookEventTypes() *bookEventTypes {
return _bookEventTypes
}
func (o *bookEventTypes) Values() []*BookEventType {
return o.values
}
func (o *bookEventTypes) Literals() []enum.Literal {
if o.literals == nil {
o.literals = make([]enum.Literal, len(o.values))
for i, item := range o.values {
o.literals[i] = item
}
}
return o.literals
}
func (o *bookEventTypes) BookCreated() *BookEventType {
return _bookEventTypes.values[0]
}
func (o *bookEventTypes) BookDeleted() *BookEventType {
return _bookEventTypes.values[1]
}
func (o *bookEventTypes) BookUpdated() *BookEventType {
return _bookEventTypes.values[2]
}
func (o *bookEventTypes) ParseBookEventType(name string) (ret *BookEventType, ok bool) {
if item, ok := enum.Parse(name, o.Literals()); ok {
return item.(*BookEventType), ok
}
return
}