Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidID = errors.New("invalid budget ID") ErrInvalidUserID = errors.New("invalid user ID") ErrEmptyName = errors.New("budget name cannot be empty") ErrInvalidAmount = errors.New("budget amount must be greater than zero") ErrInvalidCurrency = errors.New("invalid currency code") ErrInvalidPeriod = errors.New("invalid budget period") ErrInvalidDateRange = errors.New("start date must be before end date") )
Domain errors for Budget operations.
Functions ¶
This section is empty.
Types ¶
type Budget ¶
type Budget struct {
ID uuid.UUID `json:"id"`
UserID uuid.UUID `json:"user_id"`
Name string `json:"name"`
Amount float64 `json:"amount"` // Amount in major currency units
Currency string `json:"currency"`
Period Period `json:"period"`
StartDate time.Time `json:"start_date"`
EndDate time.Time `json:"end_date"`
CategoryIDs []uuid.UUID `json:"category_ids,omitempty"` // Specific categories this budget applies to; empty means general
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Budget represents a financial constraint or plan set by a user for a specific duration.
func NewBudget ¶
func NewBudget(userID uuid.UUID, name string, amount float64, currency string, period Period, start, end time.Time, categories []uuid.UUID) (*Budget, error)
NewBudget creates a new Budget entity with validation and default timestamps.
func (*Budget) IsActive ¶
IsActive checks if the budget is currently active based on the provided time.
func (*Budget) PercentUsed ¶
PercentUsed calculates the percentage of the budget that has been utilized.