예제 #1
0
파일: update.go 프로젝트: sporto/kic
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
}
예제 #2
0
파일: create.go 프로젝트: sporto/kic
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
}