-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimeEntries.go
77 lines (62 loc) · 1.76 KB
/
timeEntries.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
package alvtimeclient
import (
"encoding/json"
"net/url"
)
// TimeEntrie struct
type TimeEntrie struct {
Date string `json:"date"`
Value float32 `json:"value"`
TaskID int `json:"taskId"`
}
// GetTimeEntries fetches all the time entries available to the authenticated user
// between the dates denoted by fromDateInclusive to toDateInclusive formated as "YYYY-MM-DD"
func (c *AlvtimeClient) GetTimeEntries(
fromDateInclusive, toDateInclusive string,
) (timeEntries []TimeEntrie, err error) {
baseURL, err := url.Parse(c.domain)
if err != nil {
return nil, err
}
baseURL.Path += "/api/user/TimeEntries"
params := url.Values{}
params.Add("fromDateInclusive", fromDateInclusive)
params.Add("toDateInclusive", toDateInclusive)
baseURL.RawQuery = params.Encode()
req, err := c.newRequest("GET", baseURL, nil)
if err != nil {
return nil, err
}
byteArr, err := c.do(req)
if err != nil {
return nil, err
}
err = json.Unmarshal(byteArr, &timeEntries)
if err != nil {
return nil, err
}
return timeEntries, nil
}
// EditTimeEntries is used to edit favorite tasks by setting the Favorite
// attribute on and passing it in a slice. The edited tasks are returned as stored to confirm.
func (c *AlvtimeClient) EditTimeEntries(timeEntriesToEdit []TimeEntrie) (editedTimeEntreis []TimeEntrie, err error) {
baseURL, err := url.Parse(c.domain)
if err != nil {
return nil, err
}
baseURL.Path += "/api/user/TimeEntries"
req, err := c.newRequest("POST", baseURL, timeEntriesToEdit)
if err != nil {
return nil, err
}
req.Header.Add("Content-Type", "application/json")
byteArr, err := c.do(req)
if err != nil {
return nil, err
}
err = json.Unmarshal(byteArr, &editedTimeEntreis)
if err != nil {
return nil, err
}
return editedTimeEntreis, nil
}