Documentation
¶
Index ¶
- func ValidateBudget(budgetStr string) (int64, error)
- type Service
- func (c *Service) Create(ctx context.Context, userID int64, form domain.CategoryFormData) (int64, []domain.Expense, error)
- func (c *Service) Delete(ctx context.Context, userID, id int64) error
- func (c *Service) EnhancedList(ctx context.Context, userID int64) ([]domain.EnhancedCategory, int, int, error)
- func (c *Service) Get(ctx context.Context, userID, id int64) (domain.Category, error)
- func (c *Service) GetUncategorized(ctx context.Context, userID int64, query string) (map[string]domain.UncategorizedInfo, []string, int, int64, error)
- func (c *Service) List(ctx context.Context, userID int64) ([]domain.Category, error)
- func (c *Service) Reset(ctx context.Context, userID int64) error
- func (c *Service) Test(ctx context.Context, userID int64, pattern string) ([]domain.Expense, error)
- func (c *Service) Update(ctx context.Context, userID, categoryID int64, name, pattern, budgetStr string) (domain.Category, bool, bool, error)
- func (c *Service) UpdateCategoryPattern(ctx context.Context, userID, categoryID int64, description string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateBudget ¶
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 (*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) 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) 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 ¶
List returns all of the user's categories, excluding the special exclude category.
func (*Service) Test ¶
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).