-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathusers.go
143 lines (123 loc) · 4.37 KB
/
users.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package taigo
import (
"fmt"
"strconv"
"github.com/google/go-querystring/query"
)
// UserService is a handle to actions related to Users
//
// https://taigaio.github.io/taiga-doc/dist/api.html#users
type UserService struct {
client *Client
defaultProjectID int
Endpoint string
}
// List => https://taigaio.github.io/taiga-doc/dist/api.html#users-list
func (s *UserService) List(queryParams *UsersQueryParams) ([]User, error) {
url := s.client.MakeURL(s.Endpoint)
switch {
case queryParams != nil:
paramValues, _ := query.Values(queryParams)
url = fmt.Sprintf("%s?%s", url, paramValues.Encode())
case s.defaultProjectID != 0:
url = url + projectIDQueryParam(s.defaultProjectID)
}
var users []User
_, err := s.client.Request.Get(url, &users)
if err != nil {
return nil, err
}
return users, nil
}
// Get => https://taigaio.github.io/taiga-doc/dist/api.html#users-get
func (s *UserService) Get(userID int) (*User, error) {
url := s.client.MakeURL(s.Endpoint, strconv.Itoa(userID))
var u User
_, err := s.client.Request.Get(url, &u)
if err != nil {
return nil, err
}
return &u, nil
}
// Me => https://taigaio.github.io/taiga-doc/dist/api.html#users-me
func (s *UserService) Me() (*User, error) {
var u User
url := s.client.MakeURL(s.Endpoint, "me")
_, err := s.client.Request.Get(url, &u)
if err != nil {
return nil, err
}
return &u, nil
}
// GetStats => https://taigaio.github.io/taiga-doc/dist/api.html#users-stats
func (s *UserService) GetStats(userID int) (*UserStatsDetail, error) {
url := s.client.MakeURL(s.Endpoint, strconv.Itoa(userID), "stats")
var usd UserStatsDetail
_, err := s.client.Request.Get(url, &usd)
if err != nil {
return nil, err
}
return &usd, nil
}
// GetWatchedContent => https://taigaio.github.io/taiga-doc/dist/api.html#users-watched
//
// TODO: Implement query param filtering
func (s *UserService) GetWatchedContent(userID int) (*UserWatched, error) {
url := s.client.MakeURL(s.Endpoint, strconv.Itoa(userID), "watched")
var uw UserWatched
_, err := s.client.Request.Get(url, &uw)
if err != nil {
return nil, err
}
return &uw, nil
}
// GetLikedContent => https://taigaio.github.io/taiga-doc/dist/api.html#users-liked
//
// TODO: Implement query param filtering
func (s *UserService) GetLikedContent(userID int) (*UserLiked, error) {
url := s.client.MakeURL(s.Endpoint, strconv.Itoa(userID), "liked")
var ul UserLiked
_, err := s.client.Request.Get(url, &ul)
if err != nil {
return nil, err
}
return &ul, nil
}
// https://taigaio.github.io/taiga-doc/dist/api.html#users-voted
// func GetVotedContent(s *UserService) (User, error) {}
// Edit sends a PATCH request to edit a user
// https://taigaio.github.io/taiga-doc/dist/api.html#users-edit
func (s *UserService) Edit(user *User) (*User, error) {
url := s.client.MakeURL(s.Endpoint, strconv.Itoa(user.ID))
var u User
_, err := s.client.Request.Patch(url, &user, &u)
if err != nil {
return nil, err
}
return &u, nil
}
// Delete => https://taigaio.github.io/taiga-doc/dist/api.html#users-delete
func (s *UserService) Delete(userID int) error {
url := s.client.MakeURL(s.Endpoint, strconv.Itoa(userID))
_, err := s.client.Request.Delete(url)
if err != nil {
return err
}
return nil
}
// GetContacts => https://taigaio.github.io/taiga-doc/dist/api.html#users-get-contacts
// func GetContacts(s *UserService) (User, error) {}
// CancelUserAccount => https://taigaio.github.io/taiga-doc/dist/api.html#users-cancel
// func CancelUserAccount(s *UserService) (User, error) {}
// ChangeAvatar => https://taigaio.github.io/taiga-doc/dist/api.html#users-change-avatar
// func ChangeAvatar(s *UserService) (User, error) {}
// RemoveAvatar => https://taigaio.github.io/taiga-doc/dist/api.html#users-remove-avatar
// func RemoveAvatar(s *UserService) (User, error) {}
// ChangeEmail => https://taigaio.github.io/taiga-doc/dist/api.html#users-change-email
// func ChangeEmail(s *UserService) (User, error) {}
// ChangePassword => https://taigaio.github.io/taiga-doc/dist/api.html#users-change-password
// func ChangePassword(s *UserService) (User, error) {}
// PasswordRecovery => https://taigaio.github.io/taiga-doc/dist/api.html#users-password-recovery
// func PasswordRecovery(s *UserService) (User, error) {}
// ChangePasswordFromRecovery => https://taigaio.github.io/taiga-doc/dist/api.html#users-change-password-from-recovery
// func ChangePasswordFromRecovery(s *UserService) (User, error) {}