func (c *CalCommand) newSchedule(name string) *models.Schedule { base := models.NewSchedule() base.SetID(c.DB.NewID()) base.CreatedAt = time.Now() base.Name = name base.EndTime = base.StartTime.Add(24 * time.Hour) log.Print(base.EndTime.Year()) base.OwnerId = c.UserID base.UpdatedAt = time.Now() return base }
func (c *CalCommand) runSchedulingWeekday(args []string) int { i := -1 var err error for !models.ValidWeekday(i) { i, err = intInput(c.UI, "For which weekday?") if err != nil { c.UI.Error(fmt.Sprintf("Error with input: %s", err)) return failure } } scheduleID, ok := c.cal.WeekdaySchedules[string(i)] schedule := models.NewSchedule() if ok { schedule.Id = scheduleID if err := c.DB.PopulateByID(schedule); err != nil { c.UI.Error(fmt.Sprintf("Error populating weekday schedule: %s", err)) return 1 } } else { c.UI.Output("Looks like you don't have a schedule for that day, creating one now...") weekday := c.newSchedule("Weekday Schedule") if err := c.DB.Save(weekday); err != nil { c.UI.Error(err.Error()) return failure } c.cal.WeekdaySchedules[string(i)] = weekday.Id if err = c.DB.Save(c.cal); err != nil { c.UI.Error(err.Error()) return failure } schedule = weekday } fixtures, err := schedule.Fixtures(c.DB) if err != nil { c.UI.Error(fmt.Sprintf("Error retrieving the fixtures of your weekday schedule %s", err)) return 1 } c.UI.Output(fmt.Sprintf("%s Schedule Fixtures:", time.Weekday(i))) printFixtures(c.UI, fixtures) b, err := yesNo(c.UI, "Would you like to add a fixture now?") if err != nil { return 1 } if b { f, err := createFixture(c.UI, c.UserID, c.DB) if err != nil { return 1 } schedule.IncludeFixture(f) err = c.DB.Save(schedule) if err != nil { return 1 } } return success }