client

package
v0.0.0-...-ffc2b38 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound          = errors.New("client not found")
	ErrInvalidArgument   = errors.New("client invalid argument")
	ErrInternal          = errors.New("client internal error")
	ErrTransactionDenied = errors.New("client transaction denied")
)

Set of errors for client API.

Functions

This section is empty.

Types

type Billing

type Billing struct {
	Balance          int
	Limit            int
	Date             time.Time
	LastTransactions []Transaction
}

type Client

type Client struct {
	ID      int
	Limit   int
	Balance int
}

type Core

type Core struct {
	// contains filtered or unexported fields
}

Core deals with client's business logic.

func NewCore

func NewCore(s Store) *Core

func (*Core) AddTransaction

func (c *Core) AddTransaction(ctx context.Context, clientID int, nt NewTransaction) (Client, error)

func (*Core) Billing

func (c *Core) Billing(ctx context.Context, clientID int) (Billing, error)

Billing returns info about a client and the 10 most recent transactions of this client.

func (*Core) QueryByID

func (c *Core) QueryByID(ctx context.Context, clientID int) (Client, error)

type NewTransaction

type NewTransaction struct {
	Value       int
	Type        string
	Description string
}

type Store

type Store interface {
	// ExecUnderTx executes the fn function under a transaction. If fn returns
	// an error the transaction is rolled back and the error is returned.
	ExecUnderTx(ctx context.Context, fn func(tx Store) error) error

	// QueryByID returns information about a client.
	QueryByID(ctx context.Context, clientID int) (Client, error)

	// QueryTransactions returns the most recent client's transactions.
	QueryTransactions(ctx context.Context, clientID, pageNumber, rowsPerPage int) ([]Transaction, error)

	// AddTransaction add a transaction associated with a client.
	AddTransaction(ctx context.Context, t Transaction) error

	UpdateClientBalance(ctx context.Context, clientID, balance int) (Client, error)
}

Store is used to persist client's data.

type Transaction

type Transaction struct {
	ID          uuid.UUID
	ClientID    int
	Value       int
	Type        string
	Description string
	Date        time.Time
}

Directories

Path Synopsis
store

Jump to

Keyboard shortcuts

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