示例#1
0
func (repo *CassandraActivityRepo) GetUserActivity(userId string) (types.Activity, error) {
	// get activity for user by id
	log.Printf(fmt.Sprintf("CassandraActivityRepo.GetUserActivity() - Received userId: %v", userId))

	var activity types.Activity
	var user_id string
	var err error
	err = nil

	sql := fmt.Sprintf(`SELECT user_id, device_type, 
	device_id, is_logged_in, push_token, timestamp 
	FROM activities WHERE user_id = %v LIMIT 1`, userId)

	log.Printf(sql)

	if err = session.Query(sql).Scan(&user_id, &activity.DeviceType, &activity.DeviceId,
		&activity.IsLoggedIn, &activity.PushToken, &activity.Timestamp); err != nil {
		log.Printf(fmt.Sprintf("CassandraActivityRepo.GetUserActivity() - Error: %v", err.Error()))
	} else {
		activity.UserId = uuid.Parse(user_id)
	}

	return activity, err
}
示例#2
0
func CreateUserActivity(userId string, ar types.ActivityRequest) error {
	var err error
	err = nil

	if err = utilsservice.CheckIfUserExists(userId); err == nil {
		var a types.Activity

		a.DeviceId = ar.DeviceId
		a.DeviceType = ar.DeviceType
		a.IsLoggedIn = ar.IsLoggedIn
		a.UserId = uuid.Parse(userId)
		a.PushToken = ar.PushToken

		if ar.Timestamp != 0 {
			a.Timestamp = int64(time.Unix(ar.Timestamp, 0).UTC().Unix())
		} else {
			a.Timestamp = int64(time.Now().UTC().Unix())
		}

		err = activityRepo.CreateUserActivity(a)
	}

	return err
}