Documentation ¶
Overview ¶
Package banking provides functionality for performing common banking operations like creating account, transferring money and checking current account/payments.
Index ¶
- func MakeCreateAccountEndpoint(svc BankingService) endpoint.Endpoint
- func MakeGetAccountsEndpoint(svc BankingService) endpoint.Endpoint
- func MakeGetPaymentsEndpoint(svc BankingService) endpoint.Endpoint
- func MakeHandler(svc BankingService, l log.Logger) http.Handler
- func MakeSendPaymentEndpoint(svc BankingService) endpoint.Endpoint
- type BankingService
- type Service
- func (svc *Service) CreateAccount(ctx context.Context, accountName string) (entities.Account, error)
- func (svc *Service) GetAccountsList(ctx context.Context) ([]entities.Account, error)
- func (svc *Service) GetPaymentsList(ctx context.Context) ([]entities.Payment, error)
- func (svc *Service) SendPayment(ctx context.Context, from entities.Account, to entities.Account, ...) error
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 (*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 ¶
GetAccountsList returns all the accounts which currently exist in system.
func (*Service) GetPaymentsList ¶
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)