transactions

package
Version: v0.0.0-...-a6a5f53 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	Usecase
}

Handler handles account related requests

func NewHandler

func NewHandler(public *mux.Router, admin *mux.Router, usecase Usecase) *Handler

NewHandler builds accounts handler

func (Handler) Transact

func (h Handler) Transact(r *http.Request) responses.Response

Transact executes a transaction @Summary Process a transaction @Description Process a transaction for a given account @Tags Transactions @Param Body body TransactionRequest true "Body" @Accept json @Produce json @Success 200 {object} TransactionResponse @Failure 400 "Could not parse request" @Failure 404 "Account not found" @Failure 422 "Could not process transaction due to lack of balance or available credit" @Failure 500 "Internal server error" @Router /transactions [post]

type TransactionRequest

type TransactionRequest struct {
	AccountID   vos.AccountID        `json:"account_id" example:"a37c8e2e-4507-4175-ba0e-4f649a8fbe6b" validate:"required"`
	OperationID operations.Operation `json:"operation_type_id" enums:"1,2,3,4" validate:"required"`
	Amount      vos.Money            `json:"amount" validate:"required"`
}

TransactionRequest payload

type TransactionResponse

type TransactionResponse struct {
	TransactionID vos.TransactionID `json:"transaction_id"`
}

TransactionResponse payload

type TransactionsMockUsecase

type TransactionsMockUsecase struct {
	// TransactFunc mocks the Transact method.
	TransactFunc func(ctx context.Context, accID vos.AccountID, op operations.Operation, amount vos.Money) (vos.TransactionID, error)
	// contains filtered or unexported fields
}

TransactionsMockUsecase is a mock implementation of Usecase.

func TestSomethingThatUsesUsecase(t *testing.T) {

	// make and configure a mocked Usecase
	mockedUsecase := &TransactionsMockUsecase{
		TransactFunc: func(ctx context.Context, accID vos.AccountID, op operations.Operation, amount vos.Money) (vos.TransactionID, error) {
			panic("mock out the Transact method")
		},
	}

	// use mockedUsecase in code that requires Usecase
	// and then make assertions.

}

func (*TransactionsMockUsecase) Transact

Transact calls TransactFunc.

func (*TransactionsMockUsecase) TransactCalls

func (mock *TransactionsMockUsecase) TransactCalls() []struct {
	Ctx    context.Context
	AccID  vos.AccountID
	Op     operations.Operation
	Amount vos.Money
}

TransactCalls gets all the calls that were made to Transact. Check the length with:

len(mockedUsecase.TransactCalls())

type Usecase

type Usecase interface {
	Transact(ctx context.Context, accID vos.AccountID, op operations.Operation, amount vos.Money) (vos.TransactionID, error)
}

Usecase of transactions

Jump to

Keyboard shortcuts

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