-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathviews.go
78 lines (66 loc) · 2.08 KB
/
views.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package cloudability
import (
"encoding/json"
)
const viewsEndpoint = "/views/"
// ViewsEndpoint - Cloudability Views Endpoint
type ViewsEndpoint struct {
*v3Endpoint
}
// Views endpoint
func (c *Client) Views() *ViewsEndpoint {
return &ViewsEndpoint{newV3Endpoint(c, viewsEndpoint)}
}
// ViewFilter - Cloudability ViewFilter
type ViewFilter struct {
Field string `json:"field"`
Comparator string `json:"comparator"`
Value string `json:"value"`
}
// View - Cloudabiity View
type View struct {
ID string `json:"id"`
Title string `json:"title"`
SharedWithUsers []string `json:"sharedWithUsers"`
SharedWithOrganization bool `json:"sharedWithOrganization"`
OwnerID string `json:"ownerId"`
Filters []*ViewFilter `json:"filters"`
}
// GetViews - returns all views
func (e ViewsEndpoint) GetViews() ([]View, error) {
var result v3Result[[]View]
err := e.get(e, "", &result)
return result.Result, err
}
// GetView - return a single view
func (e ViewsEndpoint) GetView(id string) (*View, error) {
var result v3Result[*View]
err := e.get(e, id, &result)
return result.Result, err
}
type viewPayload struct {
Title string `json:"title"`
SharedWithUsers []string `json:"sharedWithUsers"`
SharedWithOrganization bool `json:"sharedWithOrganization"`
Filters []ViewFilter `json:"filters"`
}
// NewView - create a new view
func (e *ViewsEndpoint) NewView(view *View) (*View, error) {
viewPayload := new(viewPayload)
jsonView, _ := json.Marshal(view)
json.Unmarshal(jsonView, viewPayload)
var result v3Result[*View]
err := e.post(e, "", viewPayload, &result)
return result.Result, err
}
// UpdateView - update a view
func (e *ViewsEndpoint) UpdateView(view *View) error {
viewPayload := new(viewPayload)
jsonView, _ := json.Marshal(view)
json.Unmarshal(jsonView, viewPayload)
return e.put(e, view.ID, viewPayload)
}
// DeleteView - delete a view
func (e *ViewsEndpoint) DeleteView(id string) error {
return e.delete(e, id)
}