Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 = 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.