-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathusers.go
58 lines (48 loc) · 1.03 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
package challenge
import "fmt"
type User struct {
AocID int
Name string
Username string
AvatarURL string
Team *Team
ProfileURL string
Stats map[string]Stats
}
type Stats struct {
Submissions int
Score int
Stars [25]Star
}
type Star int
const (
NoStar Star = iota
SilverStar
GoldStar
)
func GetUsersFromTeams(teams *Teams) []*User {
participantsMap := make(map[string]*User)
// load users from the participants
for _, p := range teams.Participants {
participantsMap[p.Name] = &User{
AocID: p.ID,
Username: p.Name,
AvatarURL: fmt.Sprintf("https://github.com/%s.png?size=60", p.Name),
ProfileURL: fmt.Sprintf("https://github.com/%s", p.Name),
}
}
// check if a user is part of a team
for _, t := range teams.Teams {
for _, member := range t.Members {
if m, found := participantsMap[member]; found {
m.Team = t
participantsMap[member] = m
}
}
}
users := []*User{}
for _, v := range participantsMap {
users = append(users, v)
}
return users
}