console

package
v0.20.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2019 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// DefaultPasswordCost is the hashing complexity
	DefaultPasswordCost = bcrypt.DefaultCost
	// TestPasswordCost is the hashing complexity to use for testing
	TestPasswordCost = bcrypt.MinCost
)

Variables

View Source
var ErrNoMembership = errs.Class("no membership error")

ErrNoMembership is error type of not belonging to a specific project

View Source
var ErrUnauthorized = errs.Class("unauthorized error")

ErrUnauthorized is error class for authorization related errors

View Source
var ErrValidation = errs.Class("validation error")

ErrValidation validation related error class

View Source
var NoCreditForUpdateErr = errs.Class("no credit found to update")

NoCreditForUpdateErr is a error message used when no credits are found for update when new users sign up

Functions

func WithAuth

func WithAuth(ctx context.Context, auth Authorization) context.Context

WithAuth creates new context with Authorization

func WithAuthFailure

func WithAuthFailure(ctx context.Context, err error) context.Context

WithAuthFailure creates new context with authorization failure

Types

type APIKeyInfo

type APIKeyInfo struct {
	ID        uuid.UUID `json:"id"`
	ProjectID uuid.UUID `json:"projectId"`
	PartnerID uuid.UUID `json:"partnerId"`
	Name      string    `json:"name"`
	Secret    []byte    `json:"-"`
	CreatedAt time.Time `json:"createdAt"`
}

APIKeyInfo describing api key model in the database

type APIKeys

type APIKeys interface {
	// GetByProjectID retrieves list of APIKeys for given projectID
	GetByProjectID(ctx context.Context, projectID uuid.UUID) ([]APIKeyInfo, error)
	// Get retrieves APIKeyInfo with given ID
	Get(ctx context.Context, id uuid.UUID) (*APIKeyInfo, error)
	// GetByHead retrieves APIKeyInfo for given key head
	GetByHead(ctx context.Context, head []byte) (*APIKeyInfo, error)
	// Create creates and stores new APIKeyInfo
	Create(ctx context.Context, head []byte, info APIKeyInfo) (*APIKeyInfo, error)
	// Update updates APIKeyInfo in store
	Update(ctx context.Context, key APIKeyInfo) error
	// Delete deletes APIKeyInfo from store
	Delete(ctx context.Context, id uuid.UUID) error
}

APIKeys is interface for working with api keys store

type Authorization

type Authorization struct {
	User   User
	Claims consoleauth.Claims
}

Authorization contains auth info of authorized User

func GetAuth

func GetAuth(ctx context.Context) (Authorization, error)

GetAuth gets Authorization from context

type BucketUsage added in v0.12.0

type BucketUsage struct {
	ProjectID  uuid.UUID
	BucketName string

	Storage     float64
	Egress      float64
	ObjectCount int64

	Since  time.Time
	Before time.Time
}

BucketUsage consist of total bucket usage for period

type BucketUsageCursor added in v0.12.0

type BucketUsageCursor struct {
	Search string
	Limit  uint
	Page   uint
}

BucketUsageCursor holds info for bucket usage cursor pagination

type BucketUsagePage added in v0.12.0

type BucketUsagePage struct {
	BucketUsages []BucketUsage

	Search string
	Limit  uint
	Offset uint64

	PageCount   uint
	CurrentPage uint
	TotalCount  uint64
}

BucketUsagePage represents bucket usage page result

type BucketUsageRollup added in v0.9.0

type BucketUsageRollup struct {
	ProjectID  uuid.UUID
	BucketName []byte

	RemoteStoredData float64
	InlineStoredData float64

	RemoteSegments float64
	InlineSegments float64
	ObjectCount    float64
	MetadataSize   float64

	RepairEgress float64
	GetEgress    float64
	AuditEgress  float64

	Since  time.Time
	Before time.Time
}

BucketUsageRollup is total bucket usage info for certain period

type Card added in v0.15.0

type Card struct {
	Country         string
	Brand           string
	Name            string
	ExpirationMonth int64
	ExpirationYear  int64
	LastFour        string
}

Card contains customer card info

type CreateCredit added in v0.18.0

type CreateCredit struct {
	OfferInfo     rewards.RedeemOffer
	UserID        uuid.UUID
	OfferID       int
	Type          CreditType
	ReferredBy    *uuid.UUID
	CreditsEarned currency.USD
	ExpiresAt     time.Time
}

CreateCredit holds information that's needed when create a new record of user credit

func NewCredit added in v0.18.0

func NewCredit(currentReward *rewards.Offer, creditType CreditType, userID uuid.UUID, referrerID *uuid.UUID) (*CreateCredit, error)

NewCredit returns a new credit data

type CreateUser

type CreateUser struct {
	UserInfo
	Password string `json:"password"`
}

CreateUser struct holds info for User creation.

func (*CreateUser) IsValid

func (user *CreateUser) IsValid() error

IsValid checks CreateUser validity and returns error describing whats wrong.

type CreditType added in v0.17.0

type CreditType string

CreditType indicates a type of a credit

const (
	// Invitee is a type of credits earned by invitee
	Invitee CreditType = "invitee"
	// Referrer is a type of credits earned by referrer
	Referrer CreditType = "referrer"
)

type DB

type DB interface {
	// Users is a getter for Users repository
	Users() Users
	// Projects is a getter for Projects repository
	Projects() Projects
	// ProjectMembers is a getter for ProjectMembers repository
	ProjectMembers() ProjectMembers
	// APIKeys is a getter for APIKeys repository
	APIKeys() APIKeys
	// BucketUsage is a getter for accounting.BucketUsage repository
	BucketUsage() accounting.BucketUsage
	// RegistrationTokens is a getter for RegistrationTokens repository
	RegistrationTokens() RegistrationTokens
	// ResetPasswordTokens is a getter for ResetPasswordTokens repository
	ResetPasswordTokens() ResetPasswordTokens
	// UsageRollups is a getter for UsageRollups repository
	UsageRollups() UsageRollups
	// UserCredits is a getter for UserCredits repository
	UserCredits() UserCredits
	// UserPayments is a getter for UserPayments repository
	UserPayments() UserPayments
	// ProjectPayments is a getter for ProjectPayments repository
	ProjectPayments() ProjectPayments
	// ProjectInvoiceStamps is a getter for ProjectInvoiceStamps repository
	ProjectInvoiceStamps() ProjectInvoiceStamps

	// BeginTransaction is a method for opening transaction
	BeginTx(ctx context.Context) (DBTx, error)
}

DB contains access to different satellite databases

type DBTx

type DBTx interface {
	DB
	// CommitTransaction is a method for committing and closing transaction
	Commit() error
	// RollbackTransaction is a method for rollback and closing transaction
	Rollback() error
}

DBTx extends Database with transaction scope

type Project

type Project struct {
	ID uuid.UUID `json:"id"`

	Name        string    `json:"name"`
	Description string    `json:"description"`
	UsageLimit  int64     `json:"usageLimit"`
	PartnerID   uuid.UUID `json:"partnerId"`
	OwnerID     uuid.UUID `json:"ownerId"`

	CreatedAt time.Time `json:"createdAt"`
}

Project is a database object that describes Project entity

type ProjectInfo

type ProjectInfo struct {
	Name        string `json:"name"`
	Description string `json:"description"`

	CreatedAt time.Time `json:"createdAt"`
}

ProjectInfo holds data needed to create/update Project

type ProjectInvoiceStamp added in v0.13.0

type ProjectInvoiceStamp struct {
	ProjectID uuid.UUID
	InvoiceID []byte

	StartDate time.Time
	EndDate   time.Time

	CreatedAt time.Time
}

ProjectInvoiceStamp stores a reference of an invoice created on payments service side. Used to help prevent double invoicing and to connect an invoice with console project

type ProjectInvoiceStamps added in v0.13.0

type ProjectInvoiceStamps interface {
	Create(ctx context.Context, stamp ProjectInvoiceStamp) (*ProjectInvoiceStamp, error)
	GetByProjectIDStartDate(ctx context.Context, projectID uuid.UUID, startDate time.Time) (*ProjectInvoiceStamp, error)
	GetAll(ctx context.Context, projectID uuid.UUID) ([]ProjectInvoiceStamp, error)
}

ProjectInvoiceStamps exposes methods to manage ProjectInvoiceStamp table in database

type ProjectMember

type ProjectMember struct {
	// FK on Users table.
	MemberID uuid.UUID
	// FK on Projects table.
	ProjectID uuid.UUID

	CreatedAt time.Time
}

ProjectMember is a database object that describes ProjectMember entity.

type ProjectMemberOrder

type ProjectMemberOrder int8

ProjectMemberOrder is used for querying project members in specified order

const (
	// Name indicates that we should order by full name
	Name ProjectMemberOrder = 1
	// Email indicates that we should order by email
	Email ProjectMemberOrder = 2
	// Created indicates that we should order by created date
	Created ProjectMemberOrder = 3
)

type ProjectMemberOrderDirection added in v0.17.0

type ProjectMemberOrderDirection uint8

ProjectMemberOrderDirection is used for querying project members in specific order direction

const (
	// Ascending indicates that we should order ascending
	Ascending ProjectMemberOrderDirection = 1
	// Descending indicates that we should order descending
	Descending ProjectMemberOrderDirection = 2
)

type ProjectMembers

type ProjectMembers interface {
	// GetByMemberID is a method for querying project members from the database by memberID.
	GetByMemberID(ctx context.Context, memberID uuid.UUID) ([]ProjectMember, error)
	// GetPagedByProjectID is a method for querying project members from the database by projectID and cursor
	GetPagedByProjectID(ctx context.Context, projectID uuid.UUID, cursor ProjectMembersCursor) (*ProjectMembersPage, error)
	// Insert is a method for inserting project member into the database.
	Insert(ctx context.Context, memberID, projectID uuid.UUID) (*ProjectMember, error)
	// Delete is a method for deleting project member by memberID and projectID from the database.
	Delete(ctx context.Context, memberID, projectID uuid.UUID) error
}

ProjectMembers exposes methods to manage ProjectMembers table in database.

type ProjectMembersCursor added in v0.17.0

type ProjectMembersCursor struct {
	Search         string
	Limit          uint
	Page           uint
	Order          ProjectMemberOrder
	OrderDirection ProjectMemberOrderDirection
}

ProjectMembersCursor holds info for project members cursor pagination

type ProjectMembersPage added in v0.17.0

type ProjectMembersPage struct {
	ProjectMembers []ProjectMember

	Search         string
	Limit          uint
	Order          ProjectMemberOrder
	OrderDirection ProjectMemberOrderDirection
	Offset         uint64

	PageCount   uint
	CurrentPage uint
	TotalCount  uint64
}

ProjectMembersPage represent project members page result

type ProjectPayment added in v0.13.0

type ProjectPayment struct {
	ID uuid.UUID

	ProjectID uuid.UUID
	PayerID   uuid.UUID

	PaymentMethodID []byte
	Card            Card
	IsDefault       bool

	CreatedAt time.Time
}

ProjectPayment contains project payment info

type ProjectPayments added in v0.13.0

type ProjectPayments interface {
	Create(ctx context.Context, info ProjectPayment) (*ProjectPayment, error)
	Update(ctx context.Context, info ProjectPayment) error
	Delete(ctx context.Context, projectPaymentID uuid.UUID) error
	GetByProjectID(ctx context.Context, projectID uuid.UUID) ([]*ProjectPayment, error)
	GetByID(ctx context.Context, projectPaymentID uuid.UUID) (*ProjectPayment, error)
	GetDefaultByProjectID(ctx context.Context, projectID uuid.UUID) (*ProjectPayment, error)
	GetByPayerID(ctx context.Context, payerID uuid.UUID) ([]*ProjectPayment, error)
}

ProjectPayments is project payment infos store interface

type ProjectUsage added in v0.9.0

type ProjectUsage struct {
	Storage     float64
	Egress      float64
	ObjectCount float64

	Since  time.Time
	Before time.Time
}

ProjectUsage consist of period total storage, egress and objects count per hour for certain Project

type Projects

type Projects interface {
	// GetAll is a method for querying all projects from the database.
	GetAll(ctx context.Context) ([]Project, error)
	// GetCreatedBefore retrieves all projects created before provided date
	GetCreatedBefore(ctx context.Context, before time.Time) ([]Project, error)
	// GetByUserID is a method for querying all projects from the database by userID.
	GetByUserID(ctx context.Context, userID uuid.UUID) ([]Project, error)
	// Get is a method for querying project from the database by id.
	Get(ctx context.Context, id uuid.UUID) (*Project, error)
	// Insert is a method for inserting project into the database.
	Insert(ctx context.Context, project *Project) (*Project, error)
	// Delete is a method for deleting project by Id from the database.
	Delete(ctx context.Context, id uuid.UUID) error
	// Update is a method for updating project entity.
	Update(ctx context.Context, project *Project) error
}

Projects exposes methods to manage Project table in database.

type RegistrationSecret

type RegistrationSecret [32]byte

RegistrationSecret stores secret of registration token

func NewRegistrationSecret

func NewRegistrationSecret() (RegistrationSecret, error)

NewRegistrationSecret creates new registration secret

func RegistrationSecretFromBase64

func RegistrationSecretFromBase64(s string) (RegistrationSecret, error)

RegistrationSecretFromBase64 creates new registration secret from base64 string

func (RegistrationSecret) String

func (secret RegistrationSecret) String() string

String implements Stringer

type RegistrationToken

type RegistrationToken struct {
	// Secret is PK of the table and keeps unique value forRegToken
	Secret RegistrationSecret
	// OwnerID stores current token owner ID
	OwnerID *uuid.UUID

	// ProjectLimit defines how many projects user is able to create
	ProjectLimit int `json:"projectLimit"`

	CreatedAt time.Time `json:"createdAt"`
}

RegistrationToken describing api key model in the database

type RegistrationTokens

type RegistrationTokens interface {
	// Create creates new registration token
	Create(ctx context.Context, projectLimit int) (*RegistrationToken, error)
	// GetBySecret retrieves RegTokenInfo with given Secret
	GetBySecret(ctx context.Context, secret RegistrationSecret) (*RegistrationToken, error)
	// GetByOwnerID retrieves RegTokenInfo by ownerID
	GetByOwnerID(ctx context.Context, ownerID uuid.UUID) (*RegistrationToken, error)
	// UpdateOwner updates registration token's owner
	UpdateOwner(ctx context.Context, secret RegistrationSecret, ownerID uuid.UUID) error
}

RegistrationTokens is interface for working with registration tokens

type ResetPasswordSecret added in v0.12.0

type ResetPasswordSecret [32]byte

ResetPasswordSecret stores secret of registration token

func NewResetPasswordSecret added in v0.12.0

func NewResetPasswordSecret() (ResetPasswordSecret, error)

NewResetPasswordSecret creates new reset password secret

func ResetPasswordSecretFromBase64 added in v0.12.0

func ResetPasswordSecretFromBase64(s string) (ResetPasswordSecret, error)

ResetPasswordSecretFromBase64 creates new reset password secret from base64 string

func (ResetPasswordSecret) String added in v0.12.0

func (secret ResetPasswordSecret) String() string

String implements Stringer

type ResetPasswordToken added in v0.12.0

type ResetPasswordToken struct {
	// Secret is PK of the table and keeps unique value for reset password token
	Secret ResetPasswordSecret
	// OwnerID stores current token owner ID
	OwnerID *uuid.UUID

	CreatedAt time.Time `json:"createdAt"`
}

ResetPasswordToken describing reset password model in the database

type ResetPasswordTokens added in v0.12.0

type ResetPasswordTokens interface {
	// Create creates new reset password token
	Create(ctx context.Context, ownerID uuid.UUID) (*ResetPasswordToken, error)
	// GetBySecret retrieves ResetPasswordToken with given secret
	GetBySecret(ctx context.Context, secret ResetPasswordSecret) (*ResetPasswordToken, error)
	// GetByOwnerID retrieves ResetPasswordToken by ownerID
	GetByOwnerID(ctx context.Context, ownerID uuid.UUID) (*ResetPasswordToken, error)
	// Delete deletes ResetPasswordToken by ResetPasswordSecret
	Delete(ctx context.Context, secret ResetPasswordSecret) error
}

ResetPasswordTokens is interface for working with reset password tokens

type Service

type Service struct {
	Signer
	// contains filtered or unexported fields
}

Service is handling accounts related logic

func NewService

func NewService(log *zap.Logger, signer Signer, store DB, rewards rewards.DB, pm payments.Service, passwordCost int) (*Service, error)

NewService returns new instance of Service

func (*Service) ActivateAccount

func (s *Service) ActivateAccount(ctx context.Context, activationToken string) (err error)

ActivateAccount - is a method for activating user account after registration

func (*Service) AddNewPaymentMethod added in v0.15.0

func (s *Service) AddNewPaymentMethod(ctx context.Context, paymentMethodToken string, isDefault bool, projectID uuid.UUID) (payment *ProjectPayment, err error)

AddNewPaymentMethod adds new payment method for project

func (*Service) AddProjectMembers

func (s *Service) AddProjectMembers(ctx context.Context, projectID uuid.UUID, emails []string) (users []*User, err error)

AddProjectMembers adds users by email to given project

func (*Service) Authorize

func (s *Service) Authorize(ctx context.Context) (a Authorization, err error)

Authorize validates token from context and returns authorized Authorization

func (*Service) ChangePassword

func (s *Service) ChangePassword(ctx context.Context, pass, newPass string) (err error)

ChangePassword updates password for a given user

func (*Service) CreateAPIKey

func (s *Service) CreateAPIKey(ctx context.Context, projectID uuid.UUID, name string) (_ *APIKeyInfo, _ *macaroon.APIKey, err error)

CreateAPIKey creates new api key

func (*Service) CreateMonthlyProjectInvoices added in v0.13.0

func (s *Service) CreateMonthlyProjectInvoices(ctx context.Context, date time.Time) (err error)

CreateMonthlyProjectInvoices creates invoices for all created projects on monthly basis. Edge Dates are derived from the date parameter taking UTC year and month, then adding first and last date of the month accordingly

func (*Service) CreateProject

func (s *Service) CreateProject(ctx context.Context, projectInfo ProjectInfo) (p *Project, err error)

CreateProject is a method for creating new project

func (*Service) CreateRegToken

func (s *Service) CreateRegToken(ctx context.Context, projLimit int) (_ *RegistrationToken, err error)

CreateRegToken creates new registration token. Needed for testing

func (*Service) CreateUser

func (s *Service) CreateUser(ctx context.Context, user CreateUser, tokenSecret RegistrationSecret, refUserID string) (u *User, err error)

CreateUser gets password hash value and creates new inactive User

func (*Service) DeleteAPIKeys

func (s *Service) DeleteAPIKeys(ctx context.Context, ids []uuid.UUID) (err error)

DeleteAPIKeys deletes api key by id

func (*Service) DeleteAccount

func (s *Service) DeleteAccount(ctx context.Context, password string) (err error)

DeleteAccount deletes User

func (*Service) DeleteProject

func (s *Service) DeleteProject(ctx context.Context, projectID uuid.UUID) (err error)

DeleteProject is a method for deleting project by id

func (*Service) DeleteProjectMembers

func (s *Service) DeleteProjectMembers(ctx context.Context, projectID uuid.UUID, emails []string) (err error)

DeleteProjectMembers removes users by email from given project

func (*Service) DeleteProjectPaymentMethod added in v0.15.0

func (s *Service) DeleteProjectPaymentMethod(ctx context.Context, projectPayment uuid.UUID) (err error)

DeleteProjectPaymentMethod deletes selected payment method

func (*Service) GenerateActivationToken

func (s *Service) GenerateActivationToken(ctx context.Context, id uuid.UUID, email string) (token string, err error)

GenerateActivationToken - is a method for generating activation token

func (*Service) GeneratePasswordRecoveryToken added in v0.10.0

func (s *Service) GeneratePasswordRecoveryToken(ctx context.Context, id uuid.UUID) (token string, err error)

GeneratePasswordRecoveryToken - is a method for generating password recovery token

func (*Service) GetAPIKeyInfo

func (s *Service) GetAPIKeyInfo(ctx context.Context, id uuid.UUID) (_ *APIKeyInfo, err error)

GetAPIKeyInfo retrieves api key by id

func (*Service) GetAPIKeysInfoByProjectID

func (s *Service) GetAPIKeysInfoByProjectID(ctx context.Context, projectID uuid.UUID) (info []APIKeyInfo, err error)

GetAPIKeysInfoByProjectID retrieves all api keys for a given project

func (*Service) GetBucketTotals added in v0.12.0

func (s *Service) GetBucketTotals(ctx context.Context, projectID uuid.UUID, cursor BucketUsageCursor, before time.Time) (_ *BucketUsagePage, err error)

GetBucketTotals retrieves paged bucket total usages since project creation

func (*Service) GetBucketUsageRollups added in v0.9.0

func (s *Service) GetBucketUsageRollups(ctx context.Context, projectID uuid.UUID, since, before time.Time) (_ []BucketUsageRollup, err error)

GetBucketUsageRollups retrieves summed usage rollups for every bucket of particular project for a given period

func (*Service) GetCurrentRewardByType added in v0.15.0

func (s *Service) GetCurrentRewardByType(ctx context.Context, offerType rewards.OfferType) (offer *rewards.Offer, err error)

GetCurrentRewardByType is a method for querying current active reward offer based on its type

func (*Service) GetProject

func (s *Service) GetProject(ctx context.Context, projectID uuid.UUID) (p *Project, err error)

GetProject is a method for querying project by id

func (*Service) GetProjectMembers

func (s *Service) GetProjectMembers(ctx context.Context, projectID uuid.UUID, cursor ProjectMembersCursor) (pmp *ProjectMembersPage, err error)

GetProjectMembers returns ProjectMembers for given Project

func (*Service) GetProjectPaymentMethods added in v0.15.0

func (s *Service) GetProjectPaymentMethods(ctx context.Context, projectID uuid.UUID) ([]ProjectPayment, error)

GetProjectPaymentMethods retrieves project payment methods

func (*Service) GetProjectUsage added in v0.9.0

func (s *Service) GetProjectUsage(ctx context.Context, projectID uuid.UUID, since, before time.Time) (_ *ProjectUsage, err error)

GetProjectUsage retrieves project usage for a given period

func (*Service) GetUser

func (s *Service) GetUser(ctx context.Context, id uuid.UUID) (u *User, err error)

GetUser returns User by id

func (*Service) GetUserByEmail added in v0.10.0

func (s *Service) GetUserByEmail(ctx context.Context, email string) (u *User, err error)

GetUserByEmail returns User by email

func (*Service) GetUserCreditUsage added in v0.14.0

func (s *Service) GetUserCreditUsage(ctx context.Context) (usage *UserCreditUsage, err error)

GetUserCreditUsage is a method for querying users' credit information up until now

func (*Service) GetUsersProjects

func (s *Service) GetUsersProjects(ctx context.Context) (ps []Project, err error)

GetUsersProjects is a method for querying all projects

func (*Service) ResetPassword added in v0.10.0

func (s *Service) ResetPassword(ctx context.Context, resetPasswordToken, password string) (err error)

ResetPassword - is a method for reseting user password

func (*Service) RevokeResetPasswordToken added in v0.12.0

func (s *Service) RevokeResetPasswordToken(ctx context.Context, resetPasswordToken string) (err error)

RevokeResetPasswordToken - is a method to revoke reset password token

func (*Service) SetDefaultPaymentMethod added in v0.15.0

func (s *Service) SetDefaultPaymentMethod(ctx context.Context, projectPaymentID uuid.UUID, projectID uuid.UUID) (err error)

SetDefaultPaymentMethod set default payment method for given project

func (*Service) Token

func (s *Service) Token(ctx context.Context, email, password string) (token string, err error)

Token authenticates User by credentials and returns auth token

func (*Service) UpdateAccount

func (s *Service) UpdateAccount(ctx context.Context, info UserInfo) (err error)

UpdateAccount updates User

func (*Service) UpdateProject

func (s *Service) UpdateProject(ctx context.Context, projectID uuid.UUID, description string) (p *Project, err error)

UpdateProject is a method for updating project description by id

type Signer

type Signer interface {
	Sign(data []byte) ([]byte, error)
}

Signer creates signature for provided data

type UsageRollups added in v0.9.0

type UsageRollups interface {
	GetProjectTotal(ctx context.Context, projectID uuid.UUID, since, before time.Time) (*ProjectUsage, error)
	GetBucketUsageRollups(ctx context.Context, projectID uuid.UUID, since, before time.Time) ([]BucketUsageRollup, error)
	GetBucketTotals(ctx context.Context, projectID uuid.UUID, cursor BucketUsageCursor, since, before time.Time) (*BucketUsagePage, error)
}

UsageRollups defines how console works with usage rollups

type User

type User struct {
	ID uuid.UUID `json:"id"`

	FullName  string `json:"fullName"`
	ShortName string `json:"shortName"`

	Email        string `json:"email"`
	PasswordHash []byte `json:"passwordHash"`

	Status    UserStatus `json:"status"`
	PartnerID uuid.UUID  `json:"partnerId"`

	CreatedAt time.Time `json:"createdAt"`
}

User is a database object that describes User entity.

type UserCredit added in v0.14.0

type UserCredit struct {
	ID            int
	UserID        uuid.UUID
	OfferID       int
	ReferredBy    *uuid.UUID
	Type          CreditType
	CreditsEarned currency.USD
	CreditsUsed   currency.USD
	ExpiresAt     time.Time
	CreatedAt     time.Time
}

UserCredit holds information about an user's credit

type UserCreditUsage added in v0.14.0

type UserCreditUsage struct {
	Referred         int64
	AvailableCredits currency.USD
	UsedCredits      currency.USD
}

UserCreditUsage holds information about credit usage information

type UserCredits added in v0.14.0

type UserCredits interface {
	GetCreditUsage(ctx context.Context, userID uuid.UUID, expirationEndDate time.Time) (*UserCreditUsage, error)
	Create(ctx context.Context, userCredit CreateCredit) error
	UpdateEarnedCredits(ctx context.Context, userID uuid.UUID) error
	UpdateAvailableCredits(ctx context.Context, creditsToCharge int, id uuid.UUID, billingStartDate time.Time) (remainingCharge int, err error)
}

UserCredits holds information to interact with database

type UserInfo

type UserInfo struct {
	FullName  string `json:"fullName"`
	ShortName string `json:"shortName"`
	Email     string `json:"email"`
	PartnerID string `json:"partnerId"`
}

UserInfo holds User updatable data.

func (*UserInfo) IsValid

func (user *UserInfo) IsValid() error

IsValid checks UserInfo validity and returns error describing whats wrong.

type UserPayment added in v0.13.0

type UserPayment struct {
	UserID     uuid.UUID
	CustomerID []byte

	CreatedAt time.Time
}

UserPayment represents user payment information

type UserPayments added in v0.13.0

type UserPayments interface {
	Create(ctx context.Context, info UserPayment) (*UserPayment, error)
	Get(ctx context.Context, userID uuid.UUID) (*UserPayment, error)
}

UserPayments is user payment infos store

type UserStatus

type UserStatus int

UserStatus - is used to indicate status of the users account

const (
	// Inactive is a user status that he receives after registration
	Inactive UserStatus = 0
	// Active is a user status that he receives after account activation
	Active UserStatus = 1
	// Deleted is a user status that he receives after deleting account
	Deleted UserStatus = 2
)

type Users

type Users interface {
	// Get is a method for querying user from the database by id.
	Get(ctx context.Context, id uuid.UUID) (*User, error)
	// GetByEmail is a method for querying user by email from the database.
	GetByEmail(ctx context.Context, email string) (*User, error)
	// Insert is a method for inserting user into the database.
	Insert(ctx context.Context, user *User) (*User, error)
	// Delete is a method for deleting user by Id from the database.
	Delete(ctx context.Context, id uuid.UUID) error
	// Update is a method for updating user entity.
	Update(ctx context.Context, user *User) error
}

Users exposes methods to manage User table in database.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL