transaction

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: 12 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

Overview

Package transaction provides service-level logic for handling financial transactions and insights.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTransactionNotFound = errors.New("transaction not found")
	ErrInvalidCategory     = errors.New("invalid category")
	ErrAlreadyDisputed     = errors.New("transaction is already disputed")
	ErrDisputeTimeExpired  = errors.New("transaction is too old to dispute")
)

Functions

This section is empty.

Types

type AIClient

type AIClient interface {
	GenerateText(ctx context.Context, prompt string) (string, error)
}

AIClient defines the interface for an AI service client. This abstraction allows for swapping different AI providers (e.g., OpenAI, Gemini). The actual implementation would be in a separate package (e.g., internal/client/openai).

type AIInsight

type AIInsight struct {
	GeneratedAt time.Time `json:"generated_at"`
	InsightText string    `json:"insight_text"`
	Suggestions []string  `json:"suggestions"`
}

AIInsight holds the AI-generated analysis of a user's spending habits.

type CategoryBreakdown

type CategoryBreakdown struct {
	StartDate  time.Time          `json:"start_date"`
	EndDate    time.Time          `json:"end_date"`
	TotalSpend float64            `json:"total_spend"`
	Breakdown  []CategorySpending `json:"breakdown"`
}

CategoryBreakdown represents the distribution of spending across categories.

type CategorySpending

type CategorySpending struct {
	Category    string  `json:"category"`
	TotalAmount float64 `json:"total_amount"`
	Percentage  float64 `json:"percentage"`
}

CategorySpending represents the total spending for a specific category.

type DataPoint

type DataPoint struct {
	Date   time.Time `json:"date"`
	Amount float64   `json:"amount"`
}

DataPoint represents a single point in a time-series data set, typically for charting.

type InsightService

type InsightService interface {
	GetSpendingTrends(ctx context.Context, userID string, period string) (*SpendingTrends, error)
	GetCategoryBreakdown(ctx context.Context, userID string, startDate, endDate time.Time) (*CategoryBreakdown, error)
	GenerateAIInsights(ctx context.Context, userID string) (*AIInsight, error)
	GetSpendingForecast(ctx context.Context, userID string) (*SpendingForecast, error)
}

InsightService defines the interface for transaction insight operations. It provides methods to analyze transaction data and generate meaningful reports.

func NewInsightService

func NewInsightService(repo domain.TransactionRepository, aiClient AIClient) InsightService

NewInsightService creates a new instance of the insight service. It requires a transaction repository and an AI client as dependencies.

type Repository

type Repository interface {
	GetByID(ctx context.Context, id uuid.UUID) (*domain.Transaction, error)
	List(ctx context.Context, filter domain.TransactionFilter) ([]domain.Transaction, int64, error)
	Update(ctx context.Context, tx *domain.Transaction) error
	CreateDispute(ctx context.Context, dispute *domain.Dispute) error
	GetByUserID(ctx context.Context, userID uuid.UUID) ([]domain.Transaction, error)
}

Repository defines the data access layer requirements for transactions.

type Service

type Service interface {
	GetTransaction(ctx context.Context, id uuid.UUID) (*domain.Transaction, error)
	ListTransactions(ctx context.Context, filter domain.TransactionFilter) (*domain.PaginatedResponse, error)
	CategorizeTransaction(ctx context.Context, id uuid.UUID, category domain.Category) error
	DisputeTransaction(ctx context.Context, id uuid.UUID, reason string) (*domain.Dispute, error)
	DetectAndMarkRecurring(ctx context.Context, userID uuid.UUID) error
}

Service defines the interface for transaction business logic.

func NewService

func NewService(repo Repository, logger *slog.Logger) Service

NewService creates a new instance of the transaction service.

type SpendingForecast

type SpendingForecast struct {
	ForecastPeriodDays int         `json:"forecast_period_days"`
	ProjectedSpend     float64     `json:"projected_spend"`
	ConfidenceLevel    float64     `json:"confidence_level"` // e.g., 0.85 for 85%
	ForecastedTrend    []DataPoint `json:"forecasted_trend"`
}

SpendingForecast represents a prediction of future spending.

type SpendingTrends

type SpendingTrends struct {
	Period     string      `json:"period"`
	StartDate  time.Time   `json:"start_date"`
	EndDate    time.Time   `json:"end_date"`
	TotalSpend float64     `json:"total_spend"`
	Trends     []DataPoint `json:"trends"`
}

SpendingTrends represents spending over a period of time.

Jump to

Keyboard shortcuts

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