-
Notifications
You must be signed in to change notification settings - Fork 1
/
category.go
64 lines (52 loc) · 1.28 KB
/
category.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
package toshl
import (
"net/url"
"strconv"
"time"
)
// Category represents a Toshl category
type Category struct {
ID string `json:"id"`
Name string `json:"name"`
Modified time.Time `json:"modified"`
Type string `json:"type"`
Deleted bool `json:"deleted"`
Counts CategoryCounts `json:"counts"`
}
// CategoryQueryParams represents a struct of parameters usable
// to List Categories
type CategoryQueryParams struct {
Page int
PerPage int
Since time.Time
Type string
Search string
IncludeDeleted bool
}
func (c *CategoryQueryParams) getQueryString() string {
v := url.Values{}
if c.Page > 0 {
v.Set("page", strconv.Itoa(c.Page))
}
if c.PerPage > 0 {
v.Set("per_page", strconv.Itoa(c.PerPage))
}
if !c.Since.IsZero() {
v.Set("since", c.Since.Format("2006-01-02T15:04:05Z"))
}
if c.Type != "" {
v.Set("type", c.Type)
}
if c.Search != "" {
v.Set("search", c.Search)
}
if c.IncludeDeleted {
v.Set("include_deleted", strconv.FormatBool(c.IncludeDeleted))
}
return v.Encode()
}
// CategoriesMergeParams describes how we want to merge the categories
type CategoriesMergeParams struct {
Categories []string `json:"categories"`
Category string `json:"category"`
}