Documentation
¶
Index ¶
- Variables
- type Account
- type AccountDetailsDTO
- type AccountSummaryDTO
- type ExternalLinker
- type LinkedAccount
- type LinkedAccountDTO
- type OverdraftSettingsDTO
- type Repository
- type Service
- func (s *Service) GetAccountDetails(ctx context.Context, accountID uuid.UUID) (*AccountDetailsDTO, error)
- func (s *Service) GetOverdraftSettings(ctx context.Context, accountID uuid.UUID) (*OverdraftSettingsDTO, error)
- func (s *Service) LinkExternalAccount(ctx context.Context, userID uuid.UUID, provider, publicToken string) (*LinkedAccountDTO, error)
- func (s *Service) ListUserAccounts(ctx context.Context, userID uuid.UUID) ([]*AccountSummaryDTO, error)
- func (s *Service) SetOverdraftLimit(ctx context.Context, accountID uuid.UUID, newLimit float64) error
Constants ¶
This section is empty.
Variables ¶
var ( ErrAccountNotFound = errors.New("account not found") ErrUserHasNoAccounts = errors.New("user has no accounts to link to") ErrInvalidOverdraftLimit = errors.New("invalid overdraft limit provided") ErrLinkingFailed = errors.New("failed to link external account") ErrPermissionDenied = errors.New("permission denied to perform this action") )
Custom errors for the account service layer.
Functions ¶
This section is empty.
Types ¶
type Account ¶
type Account struct {
ID uuid.UUID
UserID uuid.UUID
AccountNumber string
Balance float64
Currency string
OverdraftLimit float64
CreatedAt time.Time
UpdatedAt time.Time
}
Account represents a user's primary account within the system.
type AccountDetailsDTO ¶
type AccountDetailsDTO struct {
ID uuid.UUID `json:"id"`
AccountNumber string `json:"account_number"`
Balance float64 `json:"balance"`
Currency string `json:"currency"`
OverdraftLimit float64 `json:"overdraft_limit"`
CreatedAt time.Time `json:"created_at"`
LinkedAccounts []LinkedAccountDTO `json:"linked_accounts"`
}
type AccountSummaryDTO ¶
type ExternalLinker ¶
type ExternalLinker interface {
ExchangePublicToken(ctx context.Context, publicToken string) (accessToken string, providerAccountID string, err error)
GetAccountInfo(ctx context.Context, accessToken string) (maskedNumber string, err error)
}
ExternalLinker defines the interface for a third-party account linking service (e.g., Plaid).
type LinkedAccount ¶
type LinkedAccount struct {
ID uuid.UUID
AccountID uuid.UUID // FK to our internal Account
Provider string // e.g., "Plaid", "Stripe"
ProviderAccountID string // The ID of the account at the provider
MaskedNumber string // e.g., "****1234"
Status string // e.g., "active", "revoked"
CreatedAt time.Time
}
LinkedAccount represents an external financial account linked to a primary account.
type LinkedAccountDTO ¶
type OverdraftSettingsDTO ¶
type Repository ¶
type Repository interface {
FindByID(ctx context.Context, id uuid.UUID) (*Account, error)
FindByUserID(ctx context.Context, userID uuid.UUID) ([]*Account, error)
Update(ctx context.Context, account *Account) error
CreateLinkedAccount(ctx context.Context, linkedAccount *LinkedAccount) error
FindLinkedAccountsByAccountID(ctx context.Context, accountID uuid.UUID) ([]*LinkedAccount, error)
}
Repository defines the persistence layer interface for accounts. This allows us to swap the database implementation without changing the service logic.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides the business logic for account management.
func NewService ¶
func NewService(repo Repository, linker ExternalLinker) (*Service, error)
NewService creates a new account service instance.
func (*Service) GetAccountDetails ¶
func (s *Service) GetAccountDetails(ctx context.Context, accountID uuid.UUID) (*AccountDetailsDTO, error)
GetAccountDetails retrieves comprehensive details for a specific account, including linked accounts. It assumes authorization has been checked by a preceding layer (e.g., middleware).
func (*Service) GetOverdraftSettings ¶
func (s *Service) GetOverdraftSettings(ctx context.Context, accountID uuid.UUID) (*OverdraftSettingsDTO, error)
GetOverdraftSettings retrieves the current overdraft settings for an account.
func (*Service) LinkExternalAccount ¶
func (s *Service) LinkExternalAccount(ctx context.Context, userID uuid.UUID, provider, publicToken string) (*LinkedAccountDTO, error)
LinkExternalAccount handles the flow of linking a third-party bank account.
func (*Service) ListUserAccounts ¶
func (s *Service) ListUserAccounts(ctx context.Context, userID uuid.UUID) ([]*AccountSummaryDTO, error)
ListUserAccounts retrieves a summary of all accounts belonging to a user.
func (*Service) SetOverdraftLimit ¶
func (s *Service) SetOverdraftLimit(ctx context.Context, accountID uuid.UUID, newLimit float64) error
SetOverdraftLimit updates the overdraft protection limit for an account. It assumes the caller's identity (e.g., userID from context) has been verified to have ownership of the accountID.