Help us shape the future of Go! Take the 2026 Go Developer Survey

category

package
v0.0.26 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateBudget

func ValidateBudget(budgetStr string) (int64, error)

ValidateBudget parses and validates a monthly budget string (expressed as a decimal amount, e.g. "100.50"), returning the equivalent value in cents.

Types

type Service

type Service struct {
	// contains filtered or unexported fields
}

func New

func New(storage storage.Storage, logger *logger.Logger) *Service

func (*Service) Create

func (c *Service) Create(
	ctx context.Context,
	userID int64,
	form domain.CategoryFormData,
) (int64, []domain.Expense, error)

Create creates a new category, and categorizes any currently uncategorized expenses whose description matches the category's pattern.

func (*Service) Delete

func (c *Service) Delete(ctx context.Context, userID, id int64) error

Delete deletes a category.

func (*Service) EnhancedList

func (c *Service) EnhancedList(
	ctx context.Context,
	userID int64,
) ([]domain.EnhancedCategory, int, int, error)

EnhancedList returns all of the user's categories (excluding the exclude category) enhanced with spending statistics, along with the total number of categorized and uncategorized expenses.

func (*Service) Get

func (c *Service) Get(ctx context.Context, userID, id int64) (domain.Category, error)

Get returns a single category by ID.

func (*Service) GetUncategorized

func (c *Service) GetUncategorized(
	ctx context.Context,
	userID int64,
	query string,
) (map[string]domain.UncategorizedInfo, []string, int, int64, error)

GetUncategorized fetches uncategorized expenses (optionally filtered by query) and groups them by description, returning the grouped map, a list of keys sorted by descending count, and the overall totals.

func (*Service) List

func (c *Service) List(ctx context.Context, userID int64) ([]domain.Category, error)

List returns all of the user's categories, excluding the special exclude category.

func (*Service) Reset

func (c *Service) Reset(ctx context.Context, userID int64) error

Reset deletes all of the user's categories.

func (*Service) Test

func (c *Service) Test(ctx context.Context, userID int64, pattern string) ([]domain.Expense, error)

Test returns the uncategorized expenses that would match the given pattern, without writing anything to storage.

func (*Service) Update

func (c *Service) Update(
	ctx context.Context,
	userID, categoryID int64,
	name, pattern, budgetStr string,
) (domain.Category, bool, bool, error)

Update updates a category's name, pattern and/or monthly budget, given the raw form values (empty name/pattern/budgetStr means "keep existing"). It resolves defaults and computes whether anything actually changed internally, so callers do not need to pre-fetch the category or duplicate the diff logic. If nothing changed, no storage write is performed and changed=false is returned. If the pattern changes, it re-sweeps the user's uncategorized and current-category expenses, recategorizing them based on the new pattern set. It returns the updated category, whether anything changed, and whether the pattern specifically changed (so the caller can decide whether to refresh its own matcher).

func (*Service) UpdateCategoryPattern

func (c *Service) UpdateCategoryPattern(
	ctx context.Context,
	userID, categoryID int64,
	description string,
) error

Jump to

Keyboard shortcuts

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