func (repo *CassandraUserRepo) UpdateUser(user types.User) (types.CreateUserResponse, error) { // insert user in users var err error var response types.CreateUserResponse err = nil sql := fmt.Sprintf(`INSERT INTO users (user_id, username, facebook_access_token, twitter_access_token, google_access_token, push_token, device_type, email, password, is_test, is_anonymous, gender_preference, timestamp) VALUES (%v, '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', %v, %v, '%v', %v)`, user.UserId, user.Username, user.FacebookAccessToken, user.TwitterAccessToken, user.GoogleAccessToken, user.PushToken, user.DeviceType, user.Email, user.Password, user.IsTest, user.IsAnonymous, user.GenderPreference, user.Timestamp) log.Printf(sql) if err = session.Query(sql).Exec(); err != nil { log.Printf(fmt.Sprintf("CassandraUserRepo.UpdateUser() - Error: %v", err.Error())) } else { response.UserId = user.UserId response.Username = user.Username response.Timestamp = user.Timestamp } return response, err }
func (repo *CassandraUserRepo) CreateUser(u types.User) (types.CreateUserResponse, error) { // insert user in users var response types.CreateUserResponse var err error var sql string err = nil sql = fmt.Sprintf(`INSERT INTO users (user_id, username, facebook_access_token, twitter_access_token, google_access_token, push_token, device_type, email, password, is_test, is_anonymous, gender_preference, timestamp) VALUES (%v, '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', %v, %v, '%v', %v)`, u.UserId, u.Username, u.FacebookAccessToken, u.TwitterAccessToken, u.GoogleAccessToken, u.PushToken, u.DeviceType, u.Email, u.Password, u.IsTest, u.IsAnonymous, u.GenderPreference, u.Timestamp) log.Printf(sql) if err = session.Query(sql).Exec(); err != nil { log.Printf(fmt.Sprintf("CassandraUserRepo.CreateUser() - Error: %v", err.Error())) } else { response.UserId = u.UserId response.Username = u.Username response.Timestamp = u.Timestamp if !u.IsAnonymous { sql = fmt.Sprintf("INSERT INTO users_by_email (email, user_id) VALUES ('%v', %v)", u.Email, u.UserId) log.Printf(sql) if err = session.Query(sql).Exec(); err != nil { log.Printf(fmt.Sprintf("CreateUser - Error: %v", err.Error())) } } sql = fmt.Sprintf("INSERT INTO users_extra_info (user_id, walking_progress, timestamp) VALUES (%v, %v, %v)", u.UserId, 0, u.Timestamp) log.Printf(sql) if err = session.Query(sql).Exec(); err != nil { log.Printf(fmt.Sprintf("CassandraUserRepo.CreateUser() - Error: %v", err.Error())) } } return response, err }