Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrAccountNameWrongLength happens when the Account Name is not between 2-100 chars long. ErrAccountNameWrongLength = errors.New("'name' must be between 2 and 100 characters in length") // ErrAccountSecretWrongLength happens when the Account Secret is not between 6-100 chars long. ErrAccountSecretWrongLength = errors.New("'secret' must be between 6 and 100 characters in length") // ErrAccountBalanceNegative happens when the Account Balance is less than zero. ErrAccountBalanceNegative = errors.New("'balance' must be greater than or equal to zero") // ErrAccountCPFInvalid happens when the Account CPF is not valid. ErrAccountCPFInvalid = errors.New("'cpf' is invalid") // ErrAccountCPFAlreadyExists happens when one tries to create an account with a CPF that is already in use by another account. ErrAccountCPFAlreadyExists = errors.New("an account with this CPF already exists") // ErrAccountCreate happens when an error occurred and the account was not created. ErrAccountCreate = errors.New("could not create account") )
var ( // ErrAuthInvalidCredentials happens if the credentials are not recognized as valid. ErrAuthInvalidCredentials = errors.New("invalid credentials") // ErrAuthLogin happens when an error occurred while processing login. ErrAuthLogin = errors.New("could not login") )
var ( // ErrTransferOriginAccountRequired happens when the Transfer origin account ID is not between 2-100 chars long. ErrTransferOriginAccountRequired = errors.New("'account_origin_id' is required") // ErrTransferDestinationAccountRequired happens when the Transfer destination account ID is not between 2-100 chars long. ErrTransferDestinationAccountRequired = errors.New("'account_destination_id' is required") // ErrTransferAmountNotPositive happens when the Transfer amount is less or equal to zero. ErrTransferAmountNotPositive = errors.New("'amount' must be greater than zero") // ErrTransferSameAccount happens when the origin and destination account IDs are the same. ErrTransferSameAccount = errors.New("origin and destination accounts must not be the same") // ErrAccountCurrentBalanceInsufficient happens when the origin account balance is less than the transfer amount. ErrAccountCurrentBalanceInsufficient = errors.New("current account balance is insufficient") // ErrTransferCreate happens when an error occurred and the transfer was not created. ErrTransferCreate = errors.New("could not create transfer") )
var ( // ErrAccountFetch happens when an error occurred while fetching the accounts. ErrAccountFetch = errors.New("could not fetch accounts") )
var ( // ErrAccountGetBalance happens when an error occurred while getting the account balance. ErrAccountGetBalance = errors.New("could not get account balance") )
var ( // ErrAuthInvalidAccessToken happens when the JWT token is invalid or expired. ErrAuthInvalidAccessToken = errors.New("invalid access token") )
var ( // ErrTransferFetch happens when an error occurred while fetching the transfers. ErrTransferFetch = errors.New("could not fetch transfers") )
Functions ¶
This section is empty.
Types ¶
type AccountBalanceOutput ¶
type AccountBalanceOutput struct { ID string `json:"id" example:"16b1d860-43d3-4970-bb54-ec395908599a"` Balance float64 `json:"balance" example:"9999.99"` }
AccountBalanceOutput represents the output data of the GetBalance method.
type AccountCreateInput ¶
type AccountCreateInput struct { Name string `json:"name" example:"Bart Simpson"` CPF string `json:"cpf" example:"999.999.999-99"` Secret string `json:"secret" example:"S3cr3t"` Balance float64 `json:"balance" example:"9999.99" default:"0"` }
AccountCreateInput represents the expected input data when creating an account.
func (*AccountCreateInput) Validate ¶
func (input *AccountCreateInput) Validate() error
Validate validates the AccountCreateInput fields.
type AccountCreateOutput ¶
type AccountCreateOutput struct { ID string `json:"id" example:"16b1d860-43d3-4970-bb54-ec395908599a"` Name string `json:"name" example:"Bart Simpson"` CPF string `json:"cpf" example:"999.999.999-99"` Balance float64 `json:"balance" example:"9999.99"` CreatedAt time.Time `json:"created_at" example:"2020-12-31T23:59:59.999999-03:00"` }
AccountCreateOutput represents the output data of the create method.
type AccountFetchOutput ¶
type AccountFetchOutput struct {
AccountCreateOutput
}
AccountFetchOutput represents the output data of the fetch method.
type AccountUseCase ¶
type AccountUseCase interface { Create(ctx context.Context, accountInput AccountCreateInput) (*AccountCreateOutput, error) Fetch(ctx context.Context) ([]AccountFetchOutput, error) GetBalance(ctx context.Context, id model.AccountID) (*AccountBalanceOutput, error) }
AccountUseCase is the interface that wraps all business logic methods related to the accounts.
func NewAccountUseCase ¶
func NewAccountUseCase(accRepo repository.AccountRepository) AccountUseCase
NewAccountUseCase instantiates a new AccountUseCase.
type AuthLoginInput ¶
type AuthLoginInput struct { CPF string `json:"cpf" example:"999.999.999-99"` Secret string `json:"secret" example:"S3cr3t"` }
AuthLoginInput represents the expected input data when logging in.
type AuthTokenOutput ¶
type AuthTokenOutput struct {
AccessToken string `` /* 228-byte string literal not displayed */
}
AuthTokenOutput represents the output data of the login method.
type AuthUseCase ¶
type AuthUseCase interface { Login(ctx context.Context, loginInput AuthLoginInput) (*AuthTokenOutput, error) Authorize(ctx context.Context, accessToken string) (*jwt.RegisteredClaims, error) }
AuthUseCase is the interface that wraps all business logic methods related to authentication.
func NewAuthUseCase ¶
func NewAuthUseCase( secretKey string, accessTokenDur time.Duration, accRepo repository.AccountRepository, ) AuthUseCase
NewAuthUseCase instantiates a new AuthUseCase.
type TransferCreateInput ¶
type TransferCreateInput struct { AccountOriginID string `json:"-"` AccountDestinationID string `json:"account_destination_id" example:"ce8ba94a-2c5f-4e00-80a1-6fcb0ce7382d"` Amount float64 `json:"amount" example:"9999.99"` }
TransferCreateInput represents the expected input data when creating a transfer.
func (*TransferCreateInput) Validate ¶
func (input *TransferCreateInput) Validate() error
Validate validates the TransferCreateInput fields.
type TransferCreateOutput ¶
type TransferCreateOutput struct { ID string `json:"id" example:"e82706ef-9ffb-45a2-8081-547accd818c4"` AccountOriginID string `json:"account_origin_id" example:"16b1d860-43d3-4970-bb54-ec395908599a"` AccountDestinationID string `json:"account_destination_id" example:"ce8ba94a-2c5f-4e00-80a1-6fcb0ce7382d"` Amount float64 `json:"amount" example:"9999.99"` CreatedAt time.Time `json:"created_at" example:"2020-12-31T23:59:59.999999-03:00"` }
TransferCreateOutput represents the output data of the create method.
type TransferFetchOutput ¶
type TransferFetchOutput struct {
TransferCreateOutput
}
TransferFetchOutput represents the output data of the fetch method.
type TransferUseCase ¶
type TransferUseCase interface { Create(ctx context.Context, transferInput TransferCreateInput) (*TransferCreateOutput, error) Fetch(ctx context.Context, accountID model.AccountID) ([]TransferFetchOutput, error) }
TransferUseCase is the interface that wraps all business logic methods related to the transfers.
func NewTransferUseCase ¶
func NewTransferUseCase(trfRepo repository.TransferRepository, accRepo repository.AccountRepository) TransferUseCase
NewTransferUseCase instantiates a new TransferUseCase.