Exemplo n.º 1
0
func (repo *CassandraChatRepo) GetUserPerfectMatch(rpf types.PerfectNumber) (types.PerfectNumber, error) {
	// get match for user by id

	var perfectNumber types.PerfectNumber
	var user_id string
	var err error
	err = nil

	sql := fmt.Sprintf(`SELECT user_id, perfect_number 
	FROM perfect_numbers WHERE perfect_number < %v LIMIT 1 ALLOW FILTERING`, rpf.PerfectNumber)

	log.Printf(sql)

	if err = session.Query(sql).Scan(&user_id, &perfectNumber.PerfectNumber); err != nil {
		log.Printf(fmt.Sprintf("CassandraChatRepo.GetUserPerfectMatch() - Error: %v", err.Error()))

		sql := fmt.Sprintf("SELECT user_id, perfect_number FROM perfect_numbers LIMIT 1")

		log.Printf(sql)

		if err = session.Query(sql).Scan(&user_id, &perfectNumber.PerfectNumber); err != nil {
			log.Printf(fmt.Sprintf("CassandraChatRepo.GetUserPerfectMatch() - Error: %v", err.Error()))
		} else {
			if user_id != rpf.UserId.String() {
				perfectNumber.UserId = uuid.Parse(user_id)
			} else {
				err = errors.New("not found")
			}
		}
	} else {
		perfectNumber.UserId = uuid.Parse(user_id)
	}

	return perfectNumber, err
}
Exemplo n.º 2
0
func (repo *CassandraChatRepo) GetUserPerfectNumber(userId string) (types.PerfectNumber, error) {
	// get match for user by id
	log.Printf(fmt.Sprintf("CassandraChatRepo.GetUserPerfectNumber() - Received userId: %v", userId))

	var perfectNumber types.PerfectNumber
	var user_id string
	var err error
	err = nil

	sql := fmt.Sprintf(`SELECT user_id, perfect_number 
	FROM perfect_numbers WHERE user_id = %v LIMIT 1`, userId)

	log.Printf(sql)

	if err = session.Query(sql).Scan(&user_id, &perfectNumber.PerfectNumber); err != nil {
		log.Printf(fmt.Sprintf("CassandraChatRepo.GetUserPerfectNumber() - Error: %v", err.Error()))
	} else {
		perfectNumber.UserId = uuid.Parse(user_id)
	}

	return perfectNumber, err
}