budget

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: 6 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 (
	// ErrNotFound is returned when a requested budget cannot be found.
	ErrNotFound = errors.New("budget not found")
	// ErrInvalidInput is returned when the input data is invalid.
	ErrInvalidInput = errors.New("invalid input parameters")
	// ErrUnauthorized is returned when the user is not authorized to perform the action.
	ErrUnauthorized = errors.New("unauthorized access to budget")
)

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"`
	Currency  string    `json:"currency"`
	StartDate time.Time `json:"start_date"`
	EndDate   time.Time `json:"end_date"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

Budget represents the core domain entity for a user's budget.

type CreateBudgetRequest

type CreateBudgetRequest struct {
	UserID    uuid.UUID `json:"user_id"`
	Name      string    `json:"name"`
	Amount    float64   `json:"amount"`
	Currency  string    `json:"currency"`
	StartDate time.Time `json:"start_date"`
	EndDate   time.Time `json:"end_date"`
}

CreateBudgetRequest contains the payload for creating a new budget.

type Repository

type Repository interface {
	Create(ctx context.Context, budget *Budget) error
	GetByID(ctx context.Context, id uuid.UUID) (*Budget, error)
	GetByUserID(ctx context.Context, userID uuid.UUID) ([]*Budget, error)
	Update(ctx context.Context, budget *Budget) error
	Delete(ctx context.Context, id uuid.UUID) error
}

Repository defines the interface for budget persistence operations. This allows for dependency injection of the storage layer.

type Service

type Service interface {
	CreateBudget(ctx context.Context, req CreateBudgetRequest) (*Budget, error)
	GetBudget(ctx context.Context, id uuid.UUID) (*Budget, error)
	ListUserBudgets(ctx context.Context, userID uuid.UUID) ([]*Budget, error)
	UpdateBudget(ctx context.Context, id uuid.UUID, req UpdateBudgetRequest) (*Budget, error)
	DeleteBudget(ctx context.Context, id uuid.UUID) error
}

Service defines the interface for the budget business logic.

func NewService

func NewService(repo Repository, logger *slog.Logger) Service

NewService initializes a new Budget Service with the given repository and logger.

type UpdateBudgetRequest

type UpdateBudgetRequest struct {
	Name      *string    `json:"name,omitempty"`
	Amount    *float64   `json:"amount,omitempty"`
	Currency  *string    `json:"currency,omitempty"`
	StartDate *time.Time `json:"start_date,omitempty"`
	EndDate   *time.Time `json:"end_date,omitempty"`
}

UpdateBudgetRequest contains the payload for updating an existing budget. Pointers are used to distinguish between zero-values and unset fields.

Jump to

Keyboard shortcuts

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