forked from addcnos/youdu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
120 lines (102 loc) · 3.1 KB
/
user.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
package youdu
import (
"context"
"net/http"
"strconv"
)
type DeptDetail struct {
DeptId int `json:"deptId"`
Position string `json:"position"`
Weight int `json:"weight"`
SortId int `json:"sortId"`
}
type UserResponse struct {
UserId string `json:"userId"`
Name string `json:"name"`
Gender int `json:"gender"`
Mobile string `json:"mobile"`
Phone string `json:"phone"`
Email string `json:"email"`
Dept []int `json:"dept"`
DeptDetail []DeptDetail `json:"deptDetail"`
}
type UserItem struct {
UserId string `json:"userId"`
Name string `json:"name"`
Gender int `json:"gender"`
Mobile string `json:"mobile,omitempty"`
Phone string `json:"phone,omitempty"`
Email string `json:"email,omitempty"`
Dept []int `json:"dept"`
DeptDetail []DeptDetail `json:"deptDetail,omitempty"`
}
type DeptUserListResponse struct {
UserList []UserItem `json:"userList"`
}
type UserEnableStateResponse struct {
EnableState int `json:"enableState"`
}
type UpdateUserEnableStateRequest struct {
UserIdList []string `json:"userIdList"`
EnableState EnableState `json:"enableState"`
}
func (c *Client) GetUser(ctx context.Context, userId string) (response UserResponse, err error) {
req, err := c.newRequest(ctx, http.MethodGet, "/cgi/user/get",
withRequestAccessToken(),
withRequestEncrypt(),
withRequestParamsKV("userId", userId),
)
if err != nil {
return
}
err = c.sendRequest(req, &response, withResponseDecrypt())
return
}
func (c *Client) GetDeptUserList(ctx context.Context, deptId int) (response DeptUserListResponse, err error) {
req, err := c.newRequest(ctx, http.MethodGet, "/cgi/user/list",
withRequestAccessToken(),
withRequestEncrypt(),
withRequestParamsKV("deptId", strconv.Itoa(deptId)),
)
if err != nil {
return
}
err = c.sendRequest(req, &response, withResponseDecrypt())
return
}
func (c *Client) GetDeptUserSimpleList(ctx context.Context, deptId int) (response DeptUserListResponse, err error) {
req, err := c.newRequest(ctx, http.MethodGet, "/cgi/user/simplelist",
withRequestAccessToken(),
withRequestEncrypt(),
withRequestParamsKV("deptId", strconv.Itoa(deptId)),
)
if err != nil {
return
}
err = c.sendRequest(req, &response, withResponseDecrypt())
return
}
func (c *Client) GetUserEnableState(ctx context.Context, userId string) (response UserEnableStateResponse, err error) {
req, err := c.newRequest(ctx, http.MethodGet, "/cgi/user/enable/state",
withRequestAccessToken(),
withRequestEncrypt(),
withRequestParamsKV("userId", userId),
)
if err != nil {
return
}
err = c.sendRequest(req, &response, withResponseDecrypt())
return
}
func (c *Client) UpdateUserEnableState(ctx context.Context, request UpdateUserEnableStateRequest) (response Response, err error) {
req, err := c.newRequest(ctx, http.MethodPost, "/cgi/user/enable/stateupdate",
withRequestAccessToken(),
withRequestEncrypt(),
withRequestBody(request),
)
if err != nil {
return
}
err = c.sendRequest(req, &response)
return
}