Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrGoalNotFound = errors.New("financial goal not found") 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 ¶
IsAchieved checks if the goal target has been met
func (*Goal) ProgressPercentage ¶
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