Documentation
¶
Index ¶
- Variables
- type Goal
- func (g *Goal) Archive()
- func (g *Goal) Deposit(amount int64) error
- func (g *Goal) IsOnTrack() bool
- func (g *Goal) MarkCompleted() error
- func (g *Goal) ProgressPercentage() float64
- func (g *Goal) RemainingAmount() int64
- func (g *Goal) String() string
- func (g *Goal) UpdateDetails(name, description string, targetAmount int64, targetDate time.Time, ...) error
- func (g *Goal) Withdraw(amount int64) error
- type Priority
- type Status
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidID = errors.New("id cannot be empty") ErrInvalidUserID = errors.New("user id cannot be empty") ErrInvalidName = errors.New("goal name cannot be empty") ErrInvalidTargetAmount = errors.New("target amount must be greater than zero") ErrInvalidCurrency = errors.New("currency code must be valid (e.g., USD, EUR)") ErrTargetDateInPast = errors.New("target date must be in the future") ErrNegativeContribution = errors.New("contribution amount cannot be negative") ErrInsufficientFunds = errors.New("insufficient funds in goal to withdraw") ErrGoalAlreadyCompleted = errors.New("goal is already marked as completed") ErrGoalArchived = errors.New("cannot modify an archived goal") )
Common domain errors for Financial Goals.
Functions ¶
This section is empty.
Types ¶
type Goal ¶
type Goal struct {
ID string `json:"id"`
UserID string `json:"user_id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
TargetAmount int64 `json:"target_amount"` // Stored in minor units (e.g., cents)
CurrentAmount int64 `json:"current_amount"` // Stored in minor units (e.g., cents)
Currency string `json:"currency"` // ISO 4217 Currency Code
TargetDate time.Time `json:"target_date"`
Status Status `json:"status"`
Priority Priority `json:"priority"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Goal represents a financial target a user wants to achieve. It encapsulates the state and business logic for tracking progress.
func New ¶
func New(id, userID, name, description, currency string, targetAmount int64, targetDate time.Time, priority Priority) (*Goal, error)
New creates a new Goal entity with validation. amount is expected in minor units (e.g., 1000 = $10.00).
func (*Goal) Archive ¶
func (g *Goal) Archive()
Archive moves the goal to an archived state, making it read-only.
func (*Goal) IsOnTrack ¶
IsOnTrack checks if the goal is on track based on time elapsed vs money saved. This is a simple linear projection.
func (*Goal) MarkCompleted ¶
MarkCompleted changes the status to Completed.
func (*Goal) ProgressPercentage ¶
ProgressPercentage calculates the completion percentage (0-100).
func (*Goal) RemainingAmount ¶
RemainingAmount returns how much is left to reach the target.