forked from nscuro/dtrack-client
-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
project_property.go
71 lines (57 loc) · 1.89 KB
/
project_property.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
package dtrack
import (
"context"
"fmt"
"net/http"
"github.com/google/uuid"
)
type ProjectProperty struct {
Group string `json:"groupName"`
Name string `json:"propertyName"`
Value string `json:"propertyValue"`
Type string `json:"propertyType"`
Description string `json:"description"`
}
type ProjectPropertyService struct {
client *Client
}
func (ps ProjectPropertyService) GetAll(ctx context.Context, projectUUID uuid.UUID, po PageOptions) (p Page[ProjectProperty], err error) {
req, err := ps.client.newRequest(ctx, http.MethodGet, fmt.Sprintf("/api/v1/project/%s/property", projectUUID), withPageOptions(po))
if err != nil {
return
}
res, err := ps.client.doRequest(req, &p.Items)
if err != nil {
return
}
p.TotalCount = res.TotalCount
return
}
func (ps ProjectPropertyService) Create(ctx context.Context, projectUUID uuid.UUID, property ProjectProperty) (p ProjectProperty, err error) {
req, err := ps.client.newRequest(ctx, http.MethodPut, fmt.Sprintf("/api/v1/project/%s/property", projectUUID), withBody(property))
if err != nil {
return
}
_, err = ps.client.doRequest(req, &p)
return
}
func (ps ProjectPropertyService) Update(ctx context.Context, projectUUID uuid.UUID, property ProjectProperty) (p ProjectProperty, err error) {
req, err := ps.client.newRequest(ctx, http.MethodPost, fmt.Sprintf("/api/v1/project/%s/property", projectUUID), withBody(property))
if err != nil {
return
}
_, err = ps.client.doRequest(req, &p)
return
}
func (ps ProjectPropertyService) Delete(ctx context.Context, projectUUID uuid.UUID, groupName, propertyName string) (err error) {
property := ProjectProperty{
Group: groupName,
Name: propertyName,
}
req, err := ps.client.newRequest(ctx, http.MethodDelete, fmt.Sprintf("/api/v1/project/%s/property", projectUUID), withBody(property))
if err != nil {
return
}
_, err = ps.client.doRequest(req, nil)
return
}