-
Notifications
You must be signed in to change notification settings - Fork 24
/
registrar.go
45 lines (36 loc) · 971 Bytes
/
registrar.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
package services
import "github.com/cloudfoundry-incubator/notifications/v1/models"
type Registrar struct {
clientsRepo ClientsRepo
kindsRepo KindsRepo
}
func NewRegistrar(clientsRepo ClientsRepo, kindsRepo KindsRepo) Registrar {
return Registrar{
clientsRepo: clientsRepo,
kindsRepo: kindsRepo,
}
}
func (registrar Registrar) Register(conn ConnectionInterface, client models.Client, kinds []models.Kind) error {
_, err := registrar.clientsRepo.Upsert(conn, client)
if err != nil {
return err
}
for _, kind := range kinds {
if kind.ID == "" {
continue
}
_, err := registrar.kindsRepo.Upsert(conn, kind)
if err != nil {
return err
}
}
return nil
}
func (registrar Registrar) Prune(conn ConnectionInterface, client models.Client, kinds []models.Kind) error {
kindIDs := []string{}
for _, kind := range kinds {
kindIDs = append(kindIDs, kind.ID)
}
_, err := registrar.kindsRepo.Trim(conn, client.ID, kindIDs)
return err
}