-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice.go
64 lines (49 loc) · 1.09 KB
/
service.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 flourish
type StrainService struct {
Strains StrainRepository
}
func (s StrainService) Get(id uint64) (*Strain, error) {
return s.Strains.Get(id)
}
func (s StrainService) Create(name string, race string, flavors []string, effects StrainEffects) (*Strain, error) {
strain := &Strain{
Name: name,
Race: race,
Flavors: flavors,
Effects: effects,
}
err := s.Strains.Create(strain)
if err != nil {
return nil, err
}
return strain, nil
}
func (s StrainService) Update(id uint64, name *string, race *string, flavors *[]string, effects *StrainEffects) error {
strain, err := s.Get(id)
if err != nil {
return err
}
if name != nil {
strain.Name = *name
}
if race != nil {
strain.Race = *race
}
if flavors != nil {
strain.Flavors = *flavors
}
if effects != nil {
strain.Effects = *effects
}
err = s.Strains.Save(strain)
if err != nil {
return err
}
return nil
}
func (s StrainService) Remove(id uint64) error {
return s.Strains.Delete(id)
}
func (s StrainService) Search(options StrainSearchOptions) ([]*Strain, error) {
return s.Strains.Search(options)
}