forked from open-networks/go-msgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Users.go
82 lines (73 loc) · 2.25 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
package msgraph
import (
"fmt"
"strings"
)
// Users represents multiple Users, used in JSON unmarshal
type Users []User
// GetUserByShortName returns the first User object that has the given shortName.
// Will return an error ErrFindUser if the user cannot be found
func (u Users) GetUserByShortName(shortName string) (User, error) {
for _, user := range u {
if user.GetShortName() == shortName {
return user, nil
}
}
return User{}, ErrFindUser
}
// GetUserByActivePhone returns the User-instance whose activeNumber equals the given phone number.
// Will return an error ErrFindUser if the user cannot be found
func (u Users) GetUserByActivePhone(activePhone string) (User, error) {
for _, user := range u {
if user.GetActivePhone() == activePhone {
return user, nil
}
}
return User{}, ErrFindUser
}
// GetUserByMail returns the User-instance that e-mail address matches the given e-mail addr.
// Will return an error ErrFindUser if the user cannot be found.
func (u Users) GetUserByMail(email string) (User, error) {
for _, user := range u {
if user.Mail == email {
return user, nil
}
}
return User{}, ErrFindUser
}
func (u Users) String() string {
var strs = make([]string, len(u))
for i, user := range u {
strs[i] = user.String()
}
return fmt.Sprintf("Users(%v)", strings.Join(strs, ", "))
}
// PrettySimpleString returns the whole []Users pretty simply formatted for logging purposes
func (u Users) PrettySimpleString() string {
var strs = make([]string, len(u))
for i, user := range u {
strs[i] = user.PrettySimpleString()
}
return fmt.Sprintf("Users(%v)", strings.Join(strs, ", "))
}
// setGraphClient sets the GraphClient within that particular instance. Hence it's directly created by GraphClient
func (u Users) setGraphClient(gC *GraphClient) Users {
for i := range u {
u[i].setGraphClient(gC)
}
return u
}
// Equal compares the Users to the other Users and returns true
// if the two given Users are equal. Otherwise returns false
func (u Users) Equal(other Users) bool {
Outer:
for _, user := range u {
for _, toCompare := range other {
if user.Equal(toCompare) {
continue Outer
}
}
return false
}
return len(u) == len(other) // if we reach this, all users have been found, now return if len of the users are equal
}