func (serv *UpdateServ) Run(dbSession *r.Session, accountIn models.Account) (accountOut models.Account, err error) { if accountIn.Id == "" { err = errors.New("Invalid id") return } accountIn.UpdatedAt = time.Now() _, err = r.Table("accounts").Get(accountIn.Id).Update(accountIn).RunRow(dbSession) if err != nil { return } accountOut, err = new(GetServ).Run(dbSession, accountIn.Id) return }
func (serv *CreateServ) Run(dbSession *r.Session, accountIn models.Account) (accountOut models.Account, err error) { if accountIn.Id != "" { err = errors.New("Account already has an id") return } accountIn.CreatedAt = time.Now() accountIn.UpdatedAt = time.Now() response, err := r.Table("accounts").Insert(accountIn).RunWrite(dbSession) if err != nil { return } id := response.GeneratedKeys[0] accountOut, err = new(GetServ).Run(dbSession, id) return }