account

package
v0.0.0-...-b1e0156 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package account provides handlers for work with accounts in the system.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeHandler

func MakeHandler(as Service, logger kitlog.Logger) http.Handler

MakeHandler returns a handler for the account service.

Types

type Account

type Account struct {
	TableName struct{}        `json:"-" sql:"select:accounts_view,alias:accounts"`
	ID        ID              `json:"id" sql:"id,pk,type:varchar(255)"`
	Balance   decimal.Decimal `json:"balance" sql:"balance,notnull,type:'decimal(16,4)'"`
	Currency  Currency        `json:"currency" sql:"currency,notnull,type:varchar(3)"`
	Deleted   bool            `json:"-" sql:"deleted,notnull"`
}

Account is a wallet in the system.

type Currency

type Currency string

Currency type represents available currencies

const (
	CurrencyUSD Currency = "USD"
)

type ID

type ID string

ID type used for accounts identification.

type Repository

type Repository interface {
	// Store account in the repository
	Store(account *Account) error

	// Find account in the repository with specified id
	Find(id ID) (*Account, error)

	// FindAll returns all accounts registered in the system
	FindAll() []*Account

	// MarkDeleted is mark as deleted specified account in the system
	MarkDeleted(id ID) error
}

Repository interface for accounts storing and operations.

type Service

type Service interface {
	// New registers a new account in the system, with desired Balance.
	New(id ID, currency Currency, balance decimal.Decimal) error

	// Load returns a read model of an account.
	Load(id ID) (*Account, error)

	// LoadAll returns all accounts registered in the system.
	LoadAll() []*Account

	// Delete uses to delete account from the system. Actually mark it as deleted.
	Delete(id ID) error
}

Service is the interface that provides account methods.

func NewLoggingService

func NewLoggingService(logger log.Logger, s Service) Service

NewLoggingService returns a new instance of a logging Service.

func NewMetricsService

func NewMetricsService(counter metrics.Counter, latency metrics.Histogram, s Service) Service

NewMetricsService returns an instance of a metrics Service.

func NewService

func NewService(accounts Repository) Service

NewService creates an account service with necessary dependencies.

Jump to

Keyboard shortcuts

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