forked from xen0n/go-workwx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_info_helper.go
57 lines (49 loc) · 1.14 KB
/
user_info_helper.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 workwx
import (
"fmt"
"strconv"
)
func reshapeDeptInfo(
ids []int64,
orders []uint32,
leaderStatuses []int,
) []UserDeptInfo {
if len(ids) != len(orders) {
panic("should never happen")
}
if len(ids) != len(leaderStatuses) {
panic("should never happen")
}
result := make([]UserDeptInfo, len(ids))
for i := range ids {
result[i].DeptID = ids[i]
result[i].Order = orders[i]
result[i].IsLeader = leaderStatuses[i] != 0
}
return result
}
func mustFromGenderStr(x string) UserGender {
n, err := strconv.Atoi(x)
if err != nil {
panic(fmt.Sprintf("gender string parse failed: %+v", err))
}
return UserGender(n)
}
func (x respUserDetail) intoUserInfo() UserInfo {
deptInfo := reshapeDeptInfo(x.DeptIDs, x.DeptOrder, x.IsLeaderInDept)
return UserInfo{
UserID: x.UserID,
Name: x.Name,
Position: x.Position,
Departments: deptInfo,
Mobile: x.Mobile,
Gender: mustFromGenderStr(x.Gender),
Email: x.Email,
AvatarURL: x.AvatarURL,
Telephone: x.Telephone,
IsEnabled: x.IsEnabled != 0,
Alias: x.Alias,
Status: UserStatus(x.Status),
QRCodeURL: x.QRCodeURL,
}
}