account

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2025 License: Apache-2.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 AccountSummaryDTO struct {
	ID            uuid.UUID `json:"id"`
	AccountNumber string    `json:"account_number"`
	Balance       float64   `json:"balance"`
	Currency      string    `json:"currency"`
}

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 LinkedAccountDTO struct {
	ID           uuid.UUID `json:"id"`
	Provider     string    `json:"provider"`
	MaskedNumber string    `json:"masked_number"`
	Status       string    `json:"status"`
	CreatedAt    time.Time `json:"created_at"`
}

type OverdraftSettingsDTO

type OverdraftSettingsDTO struct {
	AccountID      uuid.UUID `json:"account_id"`
	OverdraftLimit float64   `json:"overdraft_limit"`
	Currency       string    `json:"currency"`
}

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.

Jump to

Keyboard shortcuts

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