/
repository.go
95 lines (75 loc) · 1.94 KB
/
repository.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
package repository
import (
"github.com/Tanibox/tania-core/src/assets/domain"
"github.com/Tanibox/tania-core/src/assets/storage"
"github.com/gofrs/uuid"
)
// Result is a struct to wrap repository result
// so its easy to use it in channel.
type Result struct {
Result interface{}
Error error
}
type FarmEvent interface {
Save(uid uuid.UUID, latestVersion int, events []interface{}) <-chan error
}
type FarmRead interface {
Save(farmRead *storage.FarmRead) <-chan error
}
func NewFarmFromHistory(events []storage.FarmEvent) *domain.Farm {
state := &domain.Farm{}
for _, v := range events {
state.Transition(v.Event)
state.Version++
}
return state
}
type AreaEvent interface {
Save(uid uuid.UUID, latestVersion int, events []interface{}) <-chan error
}
type AreaRead interface {
Save(areaRead *storage.AreaRead) <-chan error
}
func NewAreaFromHistory(events []storage.AreaEvent) *domain.Area {
state := &domain.Area{}
for _, v := range events {
state.Transition(v.Event)
state.Version++
}
return state
}
type ReservoirEvent interface {
Save(uid uuid.UUID, latestVersion int, events []interface{}) <-chan error
}
type ReservoirRead interface {
Save(reservoirRead *storage.ReservoirRead) <-chan error
}
func NewReservoirFromHistory(events []storage.ReservoirEvent) *domain.Reservoir {
state := &domain.Reservoir{}
for _, v := range events {
state.Transition(v.Event)
state.Version++
}
return state
}
type MaterialEvent interface {
Save(uid uuid.UUID, latestVersion int, events []interface{}) <-chan error
}
func NewMaterialFromHistory(events []storage.MaterialEvent) *domain.Material {
state := &domain.Material{}
for _, v := range events {
state.Transition(v.Event)
state.Version++
}
return state
}
type MaterialEventTypeWrapper struct {
Type string
Data interface{}
}
func (w MaterialEventTypeWrapper) Code() string {
return w.Type
}
type MaterialRead interface {
Save(materialRead *storage.MaterialRead) <-chan error
}