/
notifications.go
50 lines (41 loc) · 1.86 KB
/
notifications.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 nimbusec
import (
"context"
"fmt"
"net/http"
)
type NotificationService service
func (srv *NotificationService) List(ctx context.Context) ([]Notification, error) {
notifications := []Notification{}
err := srv.client.Do(ctx, http.MethodGet, "/v3/notifications", nil, ¬ifications)
return notifications, err
}
func (srv *NotificationService) ListByDomain(ctx context.Context, id DomainID) ([]Notification, error) {
notifications := []Notification{}
err := srv.client.Do(ctx, http.MethodGet, fmt.Sprintf("/v3/domains/%d/notifications", id), nil, ¬ifications)
return notifications, err
}
func (srv *NotificationService) ListByUser(ctx context.Context, id UserID) ([]Notification, error) {
notifications := []Notification{}
err := srv.client.Do(ctx, http.MethodGet, fmt.Sprintf("/v3/users/%s/notifications", id), nil, ¬ifications)
return notifications, err
}
func (srv *NotificationService) Get(ctx context.Context, id NotificationID) (Notification, error) {
notification := Notification{}
err := srv.client.Do(ctx, http.MethodGet, fmt.Sprintf("/v3/notifications/%d", id), nil, ¬ification)
return notification, err
}
func (srv *NotificationService) Create(ctx context.Context, create Notification) (Notification, error) {
notification := Notification{}
err := srv.client.Do(ctx, http.MethodPost, "/v3/notifications", create, ¬ification)
return notification, err
}
func (srv *NotificationService) Update(ctx context.Context, id NotificationID, update NotificationUpdate) (Notification, error) {
notification := Notification{}
err := srv.client.Do(ctx, http.MethodPut, fmt.Sprintf("/v3/notifications/%d", id), update, ¬ification)
return notification, err
}
func (srv *NotificationService) Delete(ctx context.Context, id NotificationID) error {
err := srv.client.Do(ctx, http.MethodDelete, fmt.Sprintf("/v3/notifications/%d", id), nil, nil)
return err
}