954ca3c6ee
* add dbx queries * add migration file * start service * Add TotalReferredCountByUserId and availableCreditsByUserID * implement UserCredits interface and UserCredit struct type * add UserCredits into consoledb * add setupData helper function * add test for update * update lock file * fix lint error * add invalidUserCredits tests * rename method * adds comments * add checks for erros in setupData * change update method to only execute one query per request * rename vairable * should return a signal from Update method if the charge is not fully complete * changes for readability * prevent sql injection * rename * improve readability
32 lines
982 B
Go
32 lines
982 B
Go
// Copyright (C) 2019 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package console
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/skyrings/skyring-common/tools/uuid"
|
|
)
|
|
|
|
// UserCredits holds information to interact with database
|
|
type UserCredits interface {
|
|
TotalReferredCount(ctx context.Context, userID uuid.UUID) (int64, error)
|
|
GetAvailableCredits(ctx context.Context, userID uuid.UUID, expirationEndDate time.Time) ([]UserCredit, error)
|
|
Create(ctx context.Context, userCredit UserCredit) (*UserCredit, error)
|
|
UpdateAvailableCredits(ctx context.Context, creditsToCharge int, id uuid.UUID, billingStartDate time.Time) (remainingCharge int, err error)
|
|
}
|
|
|
|
// UserCredit holds information about an user's credit
|
|
type UserCredit struct {
|
|
ID int
|
|
UserID uuid.UUID
|
|
OfferID int
|
|
ReferredBy uuid.UUID
|
|
CreditsEarnedInCents int
|
|
CreditsUsedInCents int
|
|
ExpiresAt time.Time
|
|
CreatedAt time.Time
|
|
}
|