This repository has been archived by the owner on Sep 21, 2023. It is now read-only.
forked from bennylope/go-harvest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entry.go
57 lines (49 loc) · 1.72 KB
/
entry.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
package harvest
import (
"fmt"
"time"
)
type EntryService struct {
Service
}
type Entry struct {
ID int `json:"id"`
UserID int `json:"user_id"`
TaskID int `json:"task_id"`
InvoiceID int `json:"invoice_id"`
ProjectID int `json:"project_id"`
Hours float64 `json:"hours"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
SpentAt Date `json:"spent_at"`
// `timer_started_at` is in Harvest's JSON response, but in entries examined
// always set to null, and is creating JSON marshalling problems, so we're
// ignoring it for now.
//TimerStartedAt time.Time `json:"timer_started_at"`
IsBilled bool `json:"is_billed"`
IsClosed bool `json:"is_closed"`
Notes string `json:"notes"`
}
type EntryResponse struct {
Entry `json:"day_entry"`
}
// Returns all entries associated with a project
func (c *EntryService) ListProject(projectID int, from time.Time, to time.Time) ([]EntryResponse, error) {
return c.entryList("projects", projectID, from, to)
}
// Returns all entries associated with a person
func (c *EntryService) ListPerson(personID int, from time.Time, to time.Time) ([]EntryResponse, error) {
return c.entryList("people", personID, from, to)
}
// entryList returns entries
func (c *EntryService) entryList(resource string, projectID int, from time.Time, to time.Time) ([]EntryResponse, error) {
// TODO check that `to` does not precede `from`
fromStr := from.Format("20060102")
toStr := to.Format("20060102")
var entries []EntryResponse
resourceURL := fmt.Sprintf("/%s/%v/entries.json?from=%v&to=%v", resource, projectID, fromStr, toStr)
if err := c.get(resourceURL, &entries); err != nil {
return nil, err
}
return entries, nil
}