goal

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 (
	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) Deposit

func (g *Goal) Deposit(amount int64) error

Deposit adds funds to the goal.

func (*Goal) IsOnTrack

func (g *Goal) IsOnTrack() bool

IsOnTrack checks if the goal is on track based on time elapsed vs money saved. This is a simple linear projection.

func (*Goal) MarkCompleted

func (g *Goal) MarkCompleted() error

MarkCompleted changes the status to Completed.

func (*Goal) ProgressPercentage

func (g *Goal) ProgressPercentage() float64

ProgressPercentage calculates the completion percentage (0-100).

func (*Goal) RemainingAmount

func (g *Goal) RemainingAmount() int64

RemainingAmount returns how much is left to reach the target.

func (*Goal) String

func (g *Goal) String() string

String implements the Stringer interface for logging.

func (*Goal) UpdateDetails

func (g *Goal) UpdateDetails(name, description string, targetAmount int64, targetDate time.Time, priority Priority) error

UpdateDetails allows changing mutable fields.

func (*Goal) Withdraw

func (g *Goal) Withdraw(amount int64) error

Withdraw removes funds from the goal.

type Priority

type Priority int

Priority indicates the importance of the financial goal.

const (
	PriorityLow    Priority = 1
	PriorityMedium Priority = 2
	PriorityHigh   Priority = 3
)

type Status

type Status string

Status represents the lifecycle state of a Goal.

const (
	StatusActive    Status = "ACTIVE"
	StatusPaused    Status = "PAUSED"
	StatusCompleted Status = "COMPLETED"
	StatusArchived  Status = "ARCHIVED"
)

Jump to

Keyboard shortcuts

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