-
Notifications
You must be signed in to change notification settings - Fork 1
/
schedule.go
58 lines (49 loc) · 1.39 KB
/
schedule.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 services
import (
"fmt"
"github.com/harborchurchla/harborbot/internal/entities"
"gopkg.in/Iwark/spreadsheet.v2"
"strings"
"time"
)
type ScheduleService struct {
client *spreadsheet.Service
sheetId string
}
func NewScheduleService(client *spreadsheet.Service, sheetId string) *ScheduleService {
return &ScheduleService{client, sheetId}
}
func (s *ScheduleService) GetByTeam(team string) (*entities.Schedule, error) {
team = strings.Title(strings.ToLower(team))
ss, err := s.client.FetchSpreadsheet(s.sheetId)
if err != nil {
return nil, fmt.Errorf("error fetching schedule spreadsheet: %v", err)
}
sheet, err := ss.SheetByTitle(strings.Title(strings.ToLower(team)))
if err != nil {
return nil, fmt.Errorf("error fetching sheet for team %s - %v", team, err)
}
var scheduleEntries []*entities.ScheduleEntry
for i, row := range sheet.Rows {
// First row is the columns
if i == 0 {
continue
}
t, err := time.Parse("1/2/2006", row[0].Value)
if err != nil {
return nil, fmt.Errorf("error parsing time for data %s - %v", row[0].Value, err)
}
scheduleEntries = append(scheduleEntries, &entities.ScheduleEntry{
Date: entities.ScheduleDate(t),
TeamMembers: row[1].Value,
Notes: row[2].Value,
})
}
return &entities.Schedule{
Team: team,
Entries: scheduleEntries,
}, nil
}
func (s *ScheduleService) GetSheetID() string {
return s.sheetId
}