Documentation ¶
Index ¶
- Constants
- Variables
- func DecodeCreateTransferRequest(_ context.Context, r *http.Request) (interface{}, error)
- func DecodeGetAccountsRequest(_ context.Context, r *http.Request) (interface{}, error)
- func DecodeGetTransfersForAccountRequest(_ context.Context, r *http.Request) (interface{}, error)
- func EncodeCreateTransferResponse(_ context.Context, w http.ResponseWriter, res interface{}) error
- func EncodeGetAccountsResponse(_ context.Context, w http.ResponseWriter, res interface{}) error
- func EncodeGetTransfersForAccountResponse(_ context.Context, w http.ResponseWriter, res interface{}) error
- func ErrorEncoder(_ context.Context, err error, w http.ResponseWriter)
- func MakeCreateTransferEndpoint(s Service) endpoint.Endpoint
- func MakeGetAccountsEndpoint(s Service) endpoint.Endpoint
- func MakeGetTransfersForAccountEndpoint(s Service) endpoint.Endpoint
- func NewHTTPHandler(endpoints Endpoints, logger log.Logger) http.Handler
- type Account
- type CommonResponse
- type CreateTransferRequest
- type CreateTransferResponse
- type Currency
- type Endpoints
- type GetAccountsRequest
- type GetAccountsResponse
- type GetTransfersForAccountRequest
- type GetTransfersForAccountResponse
- type InnerTransferActions
- type InnerTransferCallback
- type InnerTransferOrder
- type Repository
- type Service
- type Transfer
- type TransferInfo
- type TransferPart
Constants ¶
View Source
const ( Deposit = "DEPOSIT" Withdraw = "WITHDRAW" Internal = "INTERNAL" )
Transfer type enums.
View Source
const ( Incoming = "INCOMING" Outgoing = "OUTGOING" )
Direction enums.
Variables ¶
View Source
var ( ErrAccountsMustBeDifferent = errors.New("accounts_must_be_different") ErrAmountMustBePositive = errors.New("transfer_amount_must_be_positive") ErrUnsupportedCurrency = errors.New("currency_not_supported") ErrInsufficientFunds = errors.New("insufficient_funds") ErrSenderNotExists = errors.New("sender_account_not_exist") ErrReceiverNotExists = errors.New("receiver_account_not_exist") ErrSenderWrongCurrency = errors.New("sender_account_wrong_currency") ErrReceiverWrongCurrency = errors.New("receiver_account_wrong_currency") ErrEmptyTransferID = errors.New("transfer_id_is_empty") ErrEmptySenderAccountID = errors.New("sender_account_id_is_empty") ErrEmptyReceiverAccountID = errors.New("receiver_account_id_is_empty") )
Business logic level errors that provide enough information about what went wrong.
View Source
var ErrNoRowsAffected = errors.New("db_no_rows_affected")
Functions ¶
func EncodeCreateTransferResponse ¶
func EncodeCreateTransferResponse(_ context.Context, w http.ResponseWriter, res interface{}) error
func EncodeGetAccountsResponse ¶
func EncodeGetAccountsResponse(_ context.Context, w http.ResponseWriter, res interface{}) error
func EncodeGetTransfersForAccountResponse ¶
func EncodeGetTransfersForAccountResponse(_ context.Context, w http.ResponseWriter, res interface{}) error
func ErrorEncoder ¶
func ErrorEncoder(_ context.Context, err error, w http.ResponseWriter)
func MakeGetAccountsEndpoint ¶
Types ¶
type Account ¶
type Account struct { ID uuid.UUID `json:"id"` CurrencyCode string `json:"currency_code"` Balance decimal.Decimal `json:"balance"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` }
Account representation with time fields that are updated accordingly.
type CommonResponse ¶
type CommonResponse struct { Error string `json:"error,omitempty"` Result string `json:"result"` Payload interface{} `json:"payload,omitempty"` }
func NewCommonResponse ¶
func NewCommonResponse(payload interface{}, err error) CommonResponse
type CreateTransferRequest ¶
type CreateTransferRequest struct {
InnerTransferOrder
}
type CreateTransferResponse ¶
type CreateTransferResponse struct {
Err error
}
type Endpoints ¶
type Endpoints struct { CreateTransfer endpoint.Endpoint GetTransfersForAccount endpoint.Endpoint GetAccounts endpoint.Endpoint }
func NewEndpoints ¶
type GetAccountsRequest ¶
type GetAccountsRequest struct{}
type GetAccountsResponse ¶
type GetTransfersForAccountResponse ¶
type GetTransfersForAccountResponse struct { Transfers []TransferInfo Err error }
type InnerTransferActions ¶
type InnerTransferCallback ¶
type InnerTransferCallback func(sender, receiver Account, a InnerTransferActions) error
type InnerTransferOrder ¶
type InnerTransferOrder struct { ID uuid.UUID `json:"id"` SenderAccountID uuid.UUID `json:"sender_account_id"` ReceiverAccountID uuid.UUID `json:"receiver_account_id"` Amount decimal.Decimal `json:"amount"` CurrencyCode string `json:"currency_code"` }
Transfer order for system to process.
type Repository ¶
type Repository interface { GetPrecision(ctx context.Context, currency string) (precision uint, exists bool, err error) // For separation business logic errors from database errors IsTransferIDUsedError(err error) bool IsEntityNotFoundError(uuid uuid.UUID, err error) bool // locks sender and receiver and manipulates data inside db transaction, // return entity not found error if sender or receiver don't exist CreateInnerTransferTransactionWithLock(ctx context.Context, sender, receiver uuid.UUID, c InnerTransferCallback) error GetAccounts(ctx context.Context, limit uint) ([]Account, error) GetTransferInfos(ctx context.Context, accountID uuid.UUID, limit uint) ([]TransferInfo, error) }
func NewRepository ¶
func NewRepository(db *sql.DB) Repository
type Service ¶
type Service interface { CreateTransfer(ctx context.Context, order InnerTransferOrder) error GetTransfersForAccount(ctx context.Context, accountID uuid.UUID) ([]TransferInfo, error) GetAccounts(ctx context.Context) ([]Account, error) }
Business actions.
func NewService ¶
func NewService(repo Repository) Service
type TransferInfo ¶
type TransferInfo struct { ID uuid.UUID `json:"id"` AccountID uuid.UUID `json:"account_id"` CorrespondingAccountID *uuid.UUID `json:"corresponding_account_id"` Type string `json:"type"` Direction string `json:"direction"` Amount decimal.Decimal `json:"amount"` CurrencyCode string `json:"currency_code"` CreatedAt time.Time `json:"created_at"` }
Click to show internal directories.
Click to hide internal directories.