forked from emersion/neutron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
contacts.go
50 lines (38 loc) · 1.21 KB
/
contacts.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
package events
import (
"github.com/faziloub/neutron/backend"
)
type Contacts struct {
backend.ContactsBackend
events backend.EventsBackend
}
func (b *Contacts) InsertContact(user string, contact *backend.Contact) (*backend.Contact, error) {
contact, err := b.ContactsBackend.InsertContact(user, contact)
if err == nil {
event := backend.NewContactDeltaEvent(contact.ID, backend.EventCreate, contact)
b.events.InsertEvent(user, event)
}
return contact, err
}
func (b *Contacts) UpdateContact(user string, update *backend.ContactUpdate) (*backend.Contact, error) {
contact, err := b.ContactsBackend.UpdateContact(user, update)
if err == nil {
event := backend.NewContactDeltaEvent(contact.ID, backend.EventUpdate, contact)
b.events.InsertEvent(user, event)
}
return contact, err
}
func (b *Contacts) DeleteContact(user, id string) error {
err := b.ContactsBackend.DeleteContact(user, id)
if err == nil {
event := backend.NewContactDeltaEvent(id, backend.EventDelete, nil)
b.events.InsertEvent(user, event)
}
return err
}
func NewContacts(bkd backend.ContactsBackend, events backend.EventsBackend) backend.ContactsBackend {
return &Contacts{
ContactsBackend: bkd,
events: events,
}
}