Documentation
¶
Index ¶
- func CreateAccount(accountSvc *accountsvc.Service, authSvc *authsvc.Service) fiber.Handler
- func Deposit(accountSvc *accountsvc.Service, authSvc *authsvc.Service) fiber.Handler
- func GetBalance(accountSvc *accountsvc.Service, authSvc *authsvc.Service) fiber.Handler
- func GetTransactions(accountSvc *accountsvc.Service, authSvc *authsvc.Service) fiber.Handler
- func ListUserAccounts(accountSvc *accountsvc.Service, authSvc *authsvc.Service) fiber.Handler
- func Routes(app *fiber.App, accountSvc *accountsvc.Service, authSvc *authsvc.Service, ...)
- func Transfer(accountSvc *accountsvc.Service, authSvc *authsvc.Service) fiber.Handler
- func Withdraw(accountSvc *accountsvc.Service, authSvc *authsvc.Service) fiber.Handler
- type ConversionInfoDTO
- type CreateAccountRequest
- type DepositRequest
- type ExternalTarget
- type StripeConnectHandlers
- type TransactionDTO
- type TransferRequest
- type TransferResponseDTO
- type WithdrawRequest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateAccount ¶
CreateAccount returns a Fiber handler for creating a new account for the current user. It extracts the user ID from the request context, initializes the account service using the provided UnitOfWork factory, and attempts to create a new account. On success, it returns the created account as JSON. On failure, it logs the error and returns an appropriate error response. @Summary Create a new account @Description Creates a new account for the authenticated user.
You can specify the currency for the account. Returns the created account details.
@Tags accounts @Accept json @Produce json @Success 201 {object} common.Response "Account created successfully" @Failure 400 {object} common.ProblemDetails "Invalid request" @Failure 401 {object} common.ProblemDetails "Unauthorized" @Failure 429 {object} common.ProblemDetails "Too many requests" @Failure 500 {object} common.ProblemDetails "Internal server error" @Router /account [post] @Security Bearer
func Deposit ¶
Deposit returns a Fiber handler for depositing an amount into a user's account. It expects a UnitOfWork factory function as a dependency for transactional operations. The handler parses the current user ID from the request context, validates the account ID from the URL, and parses the deposit amount from the request body. If successful, it performs the deposit operation using the AccountService and returns the transaction as JSON. On error, it logs the issue and returns an appropriate JSON error response. @Summary Deposit funds into an account @Description Adds funds to the specified account. Specify the amount, currency, and optional money source. Returns the transaction details. @Tags accounts @Accept json @Produce json @Param id path string true "Account ID" @Param request body DepositRequest true "Deposit details" @Success 200 {object} common.Response "Deposit successful" @Failure 400 {object} common.ProblemDetails "Invalid request" @Failure 401 {object} common.ProblemDetails "Unauthorized" @Failure 429 {object} common.ProblemDetails "Too many requests" @Failure 500 {object} common.ProblemDetails "Internal server error" @Router /account/{id}/deposit [post] @Security Bearer
func GetBalance ¶
GetBalance returns a Fiber handler for retrieving the balance of a specific account. It expects a UnitOfWork factory function as a dependency for service instantiation. The handler extracts the current user ID from the request context and parses the account ID from the URL parameters. On success, it returns the account balance as a JSON response. On error, it logs the error and returns an appropriate JSON error response. @Summary Get account balance @Description Retrieves the current balance for the specified account. Returns the balance amount and currency. @Tags accounts @Accept json @Produce json @Param id path string true "Account ID" @Success 200 {object} common.Response "Balance fetched" @Failure 400 {object} common.ProblemDetails "Invalid request" @Failure 401 {object} common.ProblemDetails "Unauthorized" @Failure 429 {object} common.ProblemDetails "Too many requests" @Failure 500 {object} common.ProblemDetails "Internal server error" @Router /account/{id}/balance [get] @Security Bearer
func GetTransactions ¶
GetTransactions returns a Fiber handler that retrieves the list of transactions
for a specific account.
It expects a UnitOfWork factory function as a dependency for service instantiation. The handler extracts the current user ID from the request context and parses the account ID from the URL parameters. On success, it returns the transactions as a JSON response. On error, it logs the error and returns an appropriate JSON error response. @Summary Get account transactions @Description Retrieves a list of transactions for the specified account. Returns an array of transaction details. @Tags accounts @Accept json @Produce json @Param id path string true "Account ID" @Success 200 {object} common.Response "Transactions fetched" @Failure 400 {object} common.ProblemDetails "Invalid request" @Failure 401 {object} common.ProblemDetails "Unauthorized" @Failure 429 {object} common.ProblemDetails "Too many requests" @Failure 500 {object} common.ProblemDetails "Internal server error" @Router /account/{id}/transactions [get] @Security Bearer
func ListUserAccounts ¶ added in v1.4.0
ListUserAccounts returns a Fiber handler that retrieves all accounts for the authenticated user. @Summary List user accounts @Description Retrieves all accounts belonging to the authenticated user. @Tags accounts @Accept json @Produce json @Success 200 {object} common.Response{data=[]dto.AccountRead} "List of user accounts" @Failure 401 {object} common.ProblemDetails "Unauthorized" @Failure 500 {object} common.ProblemDetails "Internal server error" @Router /accounts [get] @Security Bearer
func Routes ¶
func Routes( app *fiber.App, accountSvc *accountsvc.Service, authSvc *authsvc.Service, stripeConnectSvc stripeconnectsvc.Service, cfg *config.App, )
Routes registers HTTP routes for account-related operations using the Fiber web framework. It sets up endpoints for creating accounts, depositing and withdrawing funds, retrieving account balances, and listing account transactions. All routes are protected by authentication middleware and require a valid user context.
Routes:
- POST /account : Create a new account for the authenticated user.
- POST /account/:id/deposit : Deposit funds into the specified account.
- POST /account/:id/withdraw : Withdraw funds from the specified account.
- GET /account/:id/balance : Retrieve the balance of the specified account.
- GET /account/:id/transactions : List transactions for the specified account.
func Transfer ¶
Transfer returns a Fiber handler for transferring funds between accounts. @Summary Transfer funds between accounts @Description Transfers a specified amount from one account to another. Specify the source and destination account IDs, amount, and currency. Returns the transaction details. @Tags accounts @Accept json @Produce json @Param id path string true "Source Account ID" @Param request body TransferRequest true "Transfer details" @Success 200 {object} common.Response "Transfer successful" @Failure 400 {object} common.ProblemDetails "Invalid request" @Failure 401 {object} common.ProblemDetails "Unauthorized" @Failure 422 {object} common.ProblemDetails "Unprocessable entity" @Failure 429 {object} common.ProblemDetails "Too many requests" @Failure 500 {object} common.ProblemDetails "Internal server error" @Router /account/{id}/transfer [post] @Security Bearer
func Withdraw ¶
Withdraw returns a Fiber handler for processing account withdrawal requests. It expects a UnitOfWork factory function as a dependency for transactional operations.
The handler performs the following steps:
- Retrieves the current user ID from the request context.
- Parses the account ID from the route parameters.
- Parses the withdrawal amount from the request body.
- Calls the AccountService.Withdraw method to process the withdrawal.
- Returns the transaction details as a JSON response on success.
Error responses are returned in JSON format with appropriate status codes if any step fails (e.g., invalid user ID, invalid account ID,
parsing errors, or withdrawal errors).
@Summary Withdraw funds from an account @Description Withdraws a specified amount from the user's account. Specify the amount and currency. Returns the transaction details.
@Tags accounts @Accept json @Produce json @Param id path string true "Account ID" @Param request body WithdrawRequest true "Withdrawal details" @Success 200 {object} common.Response "Withdrawal successful" @Failure 400 {object} common.ProblemDetails "Invalid request" @Failure 401 {object} common.ProblemDetails "Unauthorized" @Failure 429 {object} common.ProblemDetails "Too many requests" @Failure 500 {object} common.ProblemDetails "Internal server error" @Router /account/{id}/withdraw [post] @Security Bearer
Types ¶
type ConversionInfoDTO ¶
type ConversionInfoDTO struct {
OriginalAmount float64 `json:"original_amount"`
OriginalCurrency string `json:"original_currency"`
ConvertedAmount float64 `json:"converted_amount"`
ConvertedCurrency string `json:"converted_currency"`
ConversionRate float64 `json:"conversion_rate"`
}
ConversionInfoDTO holds conversion details for API responses.
func ToConversionInfoDTO ¶
func ToConversionInfoDTO(convInfo *exchange.RateInfo) *ConversionInfoDTO
ToConversionInfoDTO maps provider.ExchangeRate to ConversionInfoDTO.
type CreateAccountRequest ¶
type CreateAccountRequest struct {
Currency string `json:"currency" validate:"omitempty,len=3,uppercase,alpha"`
}
CreateAccountRequest represents the request body for creating a new account.
type DepositRequest ¶
type DepositRequest struct {
Amount float64 `json:"amount" xml:"amount" form:"amount" validate:"required,gt=0"`
Currency string `json:"currency" validate:"omitempty,len=3,uppercase"`
MoneySource string `json:"money_source" validate:"required,min=2,max=64"`
}
DepositRequest represents the request body for depositing funds into an account.
type ExternalTarget ¶
type ExternalTarget struct {
BankAccountNumber string `json:"bank_account_number,omitempty" validate:"omitempty,min=6,max=34"`
RoutingNumber string `json:"routing_number,omitempty" validate:"omitempty,min=6,max=12"`
ExternalWalletAddress string `json:"external_wallet_address,omitempty" validate:"omitempty,min=6,max=128"`
}
ExternalTarget represents the destination for an external withdrawal, such as a bank account or wallet.
type StripeConnectHandlers ¶ added in v1.4.0
type StripeConnectHandlers struct {
// contains filtered or unexported fields
}
func NewStripeConnectHandlers ¶ added in v1.4.0
func NewStripeConnectHandlers( stripeConnectSvc stripeconnect.Service, authSvc *authsvc.Service, ) *StripeConnectHandlers
func (*StripeConnectHandlers) GetOnboardingStatus ¶ added in v1.4.0
func (h *StripeConnectHandlers) GetOnboardingStatus(c *fiber.Ctx) error
GetOnboardingStatus checks if the authenticated user has completed the Stripe Connect onboarding process @Summary Check Stripe Connect onboarding status @Description Returns the onboarding completion status for the authenticated user's Stripe Connect account @Tags account @Accept json @Produce json @Security BearerAuth @Success 200 {object} dto.OnboardingStatusResponse @Failure 401 {object} dto.ErrorResponse @Failure 403 {object} dto.ErrorResponse @Failure 500 {object} dto.ErrorResponse @Router /stripe/account/onboard/status [get]
func (*StripeConnectHandlers) InitiateOnboarding ¶ added in v1.4.0
func (h *StripeConnectHandlers) InitiateOnboarding(c *fiber.Ctx) error
InitiateOnboarding initiates the Stripe Connect onboarding flow @Summary Initiate Stripe Connect onboarding @Description Generates a Stripe Connect onboarding URL for the authenticated user @Tags account @Produce json @Security BearerAuth @Success 200 {object} dto.InitiateOnboardingResponse @Failure 401 {object} dto.ErrorResponse @Failure 500 {object} dto.ErrorResponse @Router /stripe/account/onboard [post]
type TransactionDTO ¶
type TransactionDTO struct {
ID string `json:"id"`
UserID string `json:"user_id"`
AccountID string `json:"account_id"`
Amount float64 `json:"amount"`
Balance float64 `json:"balance"`
CreatedAt string `json:"created_at"`
Currency string `json:"currency"`
MoneySource string `json:"money_source"`
}
TransactionDTO is the API response representation of a transaction.
func ToTransactionDTO ¶
func ToTransactionDTO(tx *dto.TransactionRead) *TransactionDTO
ToTransactionDTO maps a dto.TransactionRead to a TransactionDTO.
type TransferRequest ¶
type TransferRequest struct {
Amount float64 `json:"amount" validate:"required,gt=0"`
Currency string `json:"currency" validate:"omitempty,len=3,uppercase,alpha"`
DestinationAccountID string `json:"destination_account_id" validate:"required,uuid4"`
}
TransferRequest represents the request body for transferring funds between accounts.
type TransferResponseDTO ¶
type TransferResponseDTO struct {
Outgoing *TransactionDTO `json:"outgoing_transaction"`
Incoming *TransactionDTO `json:"incoming_transaction"`
ConversionInfo *ConversionInfoDTO `json:"conversion_info"`
}
TransferResponseDTO is the API response for a transfer operation, containing both transactions and a single conversion_info field (like deposit/withdraw).
func ToTransferResponseDTO ¶
func ToTransferResponseDTO(txOut, txIn *dto.TransactionRead, convInfo *exchange.RateInfo) *TransferResponseDTO
ToTransferResponseDTO maps domain transactions and conversion info to a TransferResponseDTO with a single conversion_info field.
type WithdrawRequest ¶
type WithdrawRequest struct {
Amount float64 `json:"amount" xml:"amount" form:"amount" validate:"required,gt=0"`
Currency string `json:"currency" validate:"omitempty,len=3,uppercase"`
ExternalTarget *ExternalTarget `json:"external_target" validate:"required"`
}
WithdrawRequest represents the request body for withdrawing funds from an account.