func newTestCalendar(t *testing.T, db olddata.DB, u *oldmodels.User) *oldmodels.Calendar { c := oldmodels.NewCalendar() c.SetID(db.NewID()) c.SetOwner(u) c.CreatedAt = time.Now() c.UpdatedAt = c.CreatedAt return c }
func newCalendar(db data.DB, userID string) (*models.Calendar, error) { cal := models.NewCalendar() cal.SetID(db.NewID()) cal.CreatedAt = time.Now() cal.Name = "Main" cal.OwnerId = userID cal.UpdatedAt = time.Now() return cal, db.Save(cal) }
func (c *CalCommand) init() int { if c.UI == nil { return failure // we can't c.errorf because the user interface isn't defined } if c.DB == nil { c.errorf("no database") return failure } if c.UserID == "" { c.errorf("no user id") return failure } c.cal = models.NewCalendar() if err := c.DB.PopulateByField("owner_id", c.UserID, c.cal); err != nil { if err == data.ErrNotFound { createOneNow, err := yesNo(c.UI, "It appears you do not have a calendar, would you like to create one?") if err != nil { c.UI.Error(err.Error()) return failure } if createOneNow { cal, err := newCalendar(c.DB, c.UserID) if err != nil { c.UI.Error(err.Error()) return failure } c.cal = cal } else { c.UI.Output("Ok, you will have to create one eventually in order to use the 'elos cal' commands") return failure } } else { c.UI.Error(fmt.Sprintf("Error looking for calendar: %s", err)) return failure } } if c.cal.WeekdaySchedules == nil { c.cal.WeekdaySchedules = make(map[string]string) } if c.cal.YeardaySchedules == nil { c.cal.YeardaySchedules = make(map[string]string) } return success }