-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathteam.go
102 lines (86 loc) · 3.39 KB
/
team.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
package myradio
import (
"errors"
"fmt"
"time"
"github.com/UniversityRadioYork/myradio-go/api"
)
// Officer represents information about an officership inside a Team.
type Officer struct {
User User `json:"user"`
From time.Time
FromRaw int64 `json:"from"`
MemberOfficerID uint `json:"memberofficerid"`
Position OfficerPosition `json:"position"`
}
// Team represents a station committee team.
type Team struct {
TeamID uint `json:"teamid"`
Name string `json:"name"`
Alias string `json:"alias"`
Ordering uint `json:"ordering"`
Description string `json:"description"`
Status string `json:"status"`
Officers []Officer `json:"officers"`
}
// GetCurrentTeams retrieves all teams inside the station committee.
// This consumes one API request.
func (s *Session) GetCurrentTeams() (teams []Team, err error) {
err = s.get("/team/currentteams/").Into(&teams)
return
}
// GetTeamWithOfficers retrieves a team record with officer information for the given team name.
// This consumes one API request.
func (s *Session) GetTeamWithOfficers(teamName string) (team Team, err error) {
rq := api.NewRequestf("/team/byalias/%s", teamName)
rq.Mixins = []string{"officers"}
if err = s.do(rq).Into(&team); err != nil {
return
}
for k, v := range team.Officers {
team.Officers[k].From = time.Unix(v.FromRaw, 0)
}
return
}
// getTeamPositions retrieves the positions for a given team ID and position type.
// The amount of detail can be controlled using MyRadio mixins.
// The position parameterType is either officer, assistant or head
// This consumes one API request.
func getTeamPositions(positionType string, id int, mixins []string, s *Session) (position []Officer, err error) {
if positionType != "assistanthead" && positionType != "head" && positionType != "officer" {
return nil, errors.New("Invalid position type provided")
}
rq := api.NewRequestf(fmt.Sprintf("/team/%d/%spositions", id, positionType))
rq.Mixins = mixins
if err = s.do(rq).Into(&position); err != nil {
return
}
for k, v := range position {
position[k].From = time.Unix(v.FromRaw, 0)
if v.Position.History != nil {
for ik, iv := range v.Position.History {
position[k].Position.History[ik].From = time.Unix(iv.FromRaw, 0)
position[k].Position.History[ik].To = time.Unix(iv.ToRaw, 0)
}
}
}
return
}
// GetTeamHeadPositions retrieves all head-of-team positions for a given team ID.
// The amount of detail can be controlled using MyRadio mixins.
// This consumes one API request.
func (s *Session) GetTeamHeadPositions(id int, mixins []string) (head []Officer, err error) {
return getTeamPositions("head", id, mixins, s)
}
// GetTeamAssistantHeadPositions retrieves all assistant-head-of-team positions for a given team ID.
// The amount of detail can be controlled using MyRadio mixins.
// This consumes one API request.
func (s *Session) GetTeamAssistantHeadPositions(id int, mixins []string) (assHead []Officer, err error) {
return getTeamPositions("assistanthead", id, mixins, s)
}
// GetTeamOfficerPositions retrieves all the other officer positions for a given team ID.
// The amount of detail can be controlled using MyRadio mixins.
// This consumes one API request.
func (s *Session) GetTeamOfficerPositions(id int, mixins []string) (officer []Officer, err error) {
return getTeamPositions("officer", id, mixins, s)
}