func (repo *CassandraUserRepo) GetUserExtraInfo(userId string) (types.UserExtraInfo, error) {
	// get user extra info
	var user types.UserExtraInfo
	var user_id string
	var err error
	err = nil

	sql := fmt.Sprintf("SELECT user_id, walking_progress, timestamp FROM users_extra_info WHERE user_id = %v LIMIT 1", userId)

	log.Printf(sql)

	if err = session.Query(sql).Scan(&user_id, &user.WalkingProgress, &user.Timestamp); err != nil {
		log.Printf(fmt.Sprintf("CassandraUserRepo.GetUserExtraInfo() - Error: %v", err.Error()))
	} else {
		user.UserId = uuid.Parse(user_id)
	}

	return user, err
}
Exemple #2
0
func UpdateUserExtraInfo(userId string, uer types.UserExtraInfoRequest) error {
	var err error
	err = nil

	if err = utilsservice.CheckIfUserExists(userId); err == nil {
		if uer.WalkingProgress >= 0 && uer.WalkingProgress <= 100 {
			var ue types.UserExtraInfo

			ue.UserId = uuid.Parse(userId)
			ue.WalkingProgress = uer.WalkingProgress
			ue.Timestamp = int64(time.Now().UTC().Unix())

			err = userRepo.UpdateUserExtraInfo(ue)
		} else {
			err = errors.New("400")
		}
	}

	return err
}