/
parties.go
64 lines (54 loc) · 1.51 KB
/
parties.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
package repository
import (
"github.com/talesmud/talesmud/pkg/db"
e "github.com/talesmud/talesmud/pkg/entities"
)
//PartiesRepository repository interface
type PartiesRepository interface {
FindAll() ([]*e.Party, error)
FindByID(id string) (*e.Party, error)
//FindByName(name string) (*e.Party, error)
Store(party *e.Party) (*e.Party, error)
Update(id string, party *e.Party) error
Delete(id string) error
}
//--- Implementations
type partiesRepo struct {
*GenericRepo
}
//NewMongoDBPartiesRepository creates a new mongodb partiesrep
func NewMongoDBPartiesRepository(db *db.Client) PartiesRepository {
return &partiesRepo{
GenericRepo: &GenericRepo{
db: db,
collection: "parties",
generator: func() interface{} {
return &e.Party{}
},
},
}
}
func (pr *partiesRepo) FindAll() ([]*e.Party, error) {
results := make([]*e.Party, 0)
if err := pr.GenericRepo.FindAll(func(elem interface{}) {
results = append(results, elem.(*e.Party))
}); err != nil {
return nil, err
}
return results, nil
}
func (pr *partiesRepo) Store(party *e.Party) (*e.Party, error) {
party.Entity = e.NewEntity()
result, err := pr.GenericRepo.Store(party)
return result.(*e.Party), err
}
func (pr *partiesRepo) FindByID(id string) (*e.Party, error) {
result, err := pr.GenericRepo.FindByID(id)
return result.(*e.Party), err
}
func (pr *partiesRepo) Update(id string, party *e.Party) error {
return pr.GenericRepo.Update(party, id)
}
func (pr *partiesRepo) Delete(id string) error {
return pr.GenericRepo.Delete(id)
}