-
Notifications
You must be signed in to change notification settings - Fork 1
/
budget.go
109 lines (90 loc) · 2.29 KB
/
budget.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package toshl
import (
"net/url"
"strconv"
"strings"
"time"
)
// Budget represents a Toshl budget
type Budget struct {
ID string `json:"id"`
Name string `json:"name"`
Limit int `json:"limit"`
Amount float64 `json:"amount"`
Planned float64 `json:"planned"`
Median int `json:"median"`
Currency Currency `json:"currency"`
From string `json:"from"`
To string `json:"to"`
Rollover bool `json:"rollover"`
Modified string `json:"modified"`
Recurrence Recurrence `json:"recurrence"`
Status string `json:"status"`
Type string `json:"type"`
Order int `json:"order"`
Categories []string `json:"categories"`
}
// BudgetQueryParams represents a struct of parameters usable
// to List Budgets
type BudgetQueryParams struct {
Page int
PerPage int
Since time.Time
From time.Time
To time.Time
Tags []string
Categories []string
Accounts []string
Search string
IncludeDeleted bool
Expand bool
HasProblem bool
OneIterationOnly bool
Parent string
}
func (b *BudgetQueryParams) getQueryString() string {
v := url.Values{}
if b.Page > 0 {
v.Set("page", strconv.Itoa(b.Page))
}
if b.PerPage > 0 {
v.Set("per_page", strconv.Itoa(b.PerPage))
}
if !b.Since.IsZero() {
v.Set("since", b.Since.Format("2006-01-02T15:04:05Z"))
}
if !b.From.IsZero() {
v.Set("from", b.Since.Format("2006-01-02"))
}
if !b.To.IsZero() {
v.Set("to", b.Since.Format("2006-01-02"))
}
if len(b.Tags) > 0 {
v.Set("tags", strings.Join(b.Tags, ","))
}
if len(b.Categories) > 0 {
v.Set("categories", strings.Join(b.Categories, ","))
}
if len(b.Accounts) > 0 {
v.Set("accounts", strings.Join(b.Accounts, ","))
}
if b.Search != "" {
v.Set("search", b.Search)
}
if b.IncludeDeleted {
v.Set("include_deleted", strconv.FormatBool(b.IncludeDeleted))
}
if b.Expand {
v.Set("expand", strconv.FormatBool(b.Expand))
}
if b.HasProblem {
v.Set("has_problem", strconv.FormatBool(b.HasProblem))
}
if b.OneIterationOnly {
v.Set("one_iteration_only", strconv.FormatBool(b.OneIterationOnly))
}
if b.Parent != "" {
v.Set("parent", b.Parent)
}
return v.Encode()
}