Refactor, cleanup

This commit is contained in:
Ian Gulliver
2020-09-09 04:03:49 +00:00
parent 6f8f9b7fd9
commit 47205bd6f9
4 changed files with 193 additions and 171 deletions

63
class.go Normal file
View File

@@ -0,0 +1,63 @@
package main
import (
"fmt"
"time"
"google.golang.org/api/calendar/v3"
)
type Class struct {
Summary string
Start string
End string
Students []string
Days []time.Weekday
Zoom string
}
func (c Class) happensOnDay(t time.Time) bool {
for _, day := range c.Days {
if day == t.Weekday() {
return true
}
}
return false
}
func (c Class) buildEvent(t time.Time) *calendar.Event {
dateStr := t.Format("2006-01-02")
ev := &calendar.Event{
Summary: c.Summary,
Start: &calendar.EventDateTime{
DateTime: fmt.Sprintf("%sT%s:00", dateStr, c.Start),
TimeZone: "US/Pacific",
},
End: &calendar.EventDateTime{
DateTime: fmt.Sprintf("%sT%s:00", dateStr, c.End),
TimeZone: "US/Pacific",
},
Attendees: []*calendar.EventAttendee{},
}
attendees := c.Students
if len(attendees) == 0 {
attendees = allStudents
}
for _, student := range attendees {
ev.Attendees = append(
ev.Attendees,
&calendar.EventAttendee{
Email: student,
},
)
}
if c.Zoom != "" {
ev.Description = fmt.Sprintf(`Zoom: %s`, c.Zoom)
}
return ev
}