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 (
	ErrGoalNotFound      = errors.New("financial goal not found")
	ErrUnauthorized      = errors.New("unauthorized access to goal")
	ErrInvalidInput      = errors.New("invalid input data")
	ErrDeadlineInPast    = errors.New("deadline cannot be in the past")
	ErrTargetAmountZero  = errors.New("target amount must be greater than zero")
	ErrContributionError = errors.New("failed to process contribution")
)

Common errors for the goal service

Functions

This section is empty.

Types

type CreateGoalInput

type CreateGoalInput struct {
	Name         string    `json:"name"`
	Description  string    `json:"description"`
	TargetAmount float64   `json:"target_amount"`
	Currency     string    `json:"currency"`
	Deadline     time.Time `json:"deadline"`
}

CreateGoalInput DTO for creating a goal

type Goal

type Goal struct {
	ID            string     `json:"id"`
	UserID        string     `json:"user_id"`
	Name          string     `json:"name"`
	Description   string     `json:"description"`
	TargetAmount  float64    `json:"target_amount"`
	CurrentAmount float64    `json:"current_amount"`
	Currency      string     `json:"currency"`
	StartDate     time.Time  `json:"start_date"`
	Deadline      time.Time  `json:"deadline"`
	Status        GoalStatus `json:"status"`
	CreatedAt     time.Time  `json:"created_at"`
	UpdatedAt     time.Time  `json:"updated_at"`
}

Goal represents the domain model for a financial goal

func (*Goal) IsAchieved

func (g *Goal) IsAchieved() bool

IsAchieved checks if the goal target has been met

func (*Goal) ProgressPercentage

func (g *Goal) ProgressPercentage() float64

ProgressPercentage calculates the completion percentage

type GoalProgressOutput

type GoalProgressOutput struct {
	GoalID          string     `json:"goal_id"`
	CurrentAmount   float64    `json:"current_amount"`
	TargetAmount    float64    `json:"target_amount"`
	Percentage      float64    `json:"percentage"`
	RemainingAmount float64    `json:"remaining_amount"`
	DaysRemaining   int        `json:"days_remaining"`
	Status          GoalStatus `json:"status"`
}

GoalProgressOutput DTO for reporting progress

type GoalStatus

type GoalStatus string

GoalStatus represents the state of a financial goal

const (
	StatusActive    GoalStatus = "ACTIVE"
	StatusCompleted GoalStatus = "COMPLETED"
	StatusFailed    GoalStatus = "FAILED"
	StatusPaused    GoalStatus = "PAUSED"
)

type Repository

type Repository interface {
	Create(ctx context.Context, goal *Goal) error
	GetByID(ctx context.Context, id string) (*Goal, error)
	Update(ctx context.Context, goal *Goal) error
	Delete(ctx context.Context, id string) error
	ListByUserID(ctx context.Context, userID string, status *GoalStatus) ([]*Goal, error)
}

Repository defines the interface for goal persistence

type Service

type Service interface {
	CreateGoal(ctx context.Context, userID string, input CreateGoalInput) (*Goal, error)
	GetGoal(ctx context.Context, userID, goalID string) (*Goal, error)
	UpdateGoal(ctx context.Context, userID, goalID string, input UpdateGoalInput) (*Goal, error)
	AddContribution(ctx context.Context, userID, goalID string, amount float64) (*Goal, error)
	DeleteGoal(ctx context.Context, userID, goalID string) error
	ListUserGoals(ctx context.Context, userID string, statusFilter *GoalStatus) ([]*Goal, error)
	GetGoalProgress(ctx context.Context, userID, goalID string) (*GoalProgressOutput, error)
}

Service defines the business logic interface for goals

func NewService

func NewService(repo Repository) Service

NewService creates a new instance of the Goal Service

type UpdateGoalInput

type UpdateGoalInput struct {
	Name         *string     `json:"name"`
	Description  *string     `json:"description"`
	TargetAmount *float64    `json:"target_amount"`
	Deadline     *time.Time  `json:"deadline"`
	Status       *GoalStatus `json:"status"`
}

UpdateGoalInput DTO for updating a goal

Jump to

Keyboard shortcuts

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