banking

package
v0.0.0-...-80b4807 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package banking provides functionality for performing common banking operations like creating account, transferring money and checking current account/payments.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeCreateAccountEndpoint

func MakeCreateAccountEndpoint(svc BankingService) endpoint.Endpoint

TODO: consider switch from errors as the second result value to errors as a part of first (structured) result value

func MakeGetAccountsEndpoint

func MakeGetAccountsEndpoint(svc BankingService) endpoint.Endpoint

func MakeGetPaymentsEndpoint

func MakeGetPaymentsEndpoint(svc BankingService) endpoint.Endpoint

func MakeHandler

func MakeHandler(svc BankingService, l log.Logger) http.Handler

func MakeSendPaymentEndpoint

func MakeSendPaymentEndpoint(svc BankingService) endpoint.Endpoint

Types

type BankingService

type BankingService interface {
	CreateAccount(ctx context.Context, accountName string) (entities.Account, error)
	GetAccountsList(ctx context.Context) ([]entities.Account, error)
	GetPaymentsList(ctx context.Context) ([]entities.Payment, error)
	SendPayment(ctx context.Context, from entities.Account, to entities.Account, amount decimal.Decimal) error
}

BankingService is an abstraction which contains declarations of methods used to create/show Accounts and Payments.

type Service

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

Service is an implementation of BankingService.

func NewService

func NewService(s storage.Storage) *Service

func (*Service) CreateAccount

func (svc *Service) CreateAccount(ctx context.Context, accountName string) (entities.Account, error)

CreateAccount method accepts a Account object with Name field filled in. Tries to create a new account with this name. Returns Account entity with all the attributes set up on success.

func (*Service) GetAccountsList

func (svc *Service) GetAccountsList(ctx context.Context) ([]entities.Account, error)

GetAccountsList returns all the accounts which currently exist in system.

func (*Service) GetPaymentsList

func (svc *Service) GetPaymentsList(ctx context.Context) ([]entities.Payment, error)

GetPaymentsList returns all the payments which currently exist in system.

func (*Service) SendPayment

func (svc *Service) SendPayment(ctx context.Context, from entities.Account, to entities.Account, amount decimal.Decimal) error

SendPayment attempts to transfer 'amount' of money between 'from' and 'to' Accounts. Returns error in the following cases: - 'from' and 'to' are the same account - 'from' has insufficient funds (balance would go < 0 after transfer) - either 'from' or 'to' account is not present in system - there is an existing mismatch between Account's balance and his/her payments (checked by db trigger)

Jump to

Keyboard shortcuts

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