Documentation ¶
Index ¶
- func Any(expenses []models.Expense, condition func(models.Expense) bool) bool
- func CopyFile(filePath string) error
- func JSONToCSV(filePath string) error
- type ExpenseTracker
- func (s *ExpenseTracker) CreateExpense(description string, amount float64, date string, category string) (models.Expense, error)
- func (s *ExpenseTracker) DeleteExpense(id int) error
- func (s *ExpenseTracker) ExportExpense(typeExport string) error
- func (s *ExpenseTracker) GetSummaryExpense(month int, category string) (float64, error)
- func (s *ExpenseTracker) LoadExpenses() ([]models.Expense, error)
- func (s *ExpenseTracker) LoadExpensesByCategory(category string) ([]models.Expense, error)
- func (s *ExpenseTracker) SaveExpenses(expenses []models.Expense) error
- func (s *ExpenseTracker) UpdateExpense(id int, description string, amount float64, date string, category string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ExpenseTracker ¶
type ExpenseTracker struct {
// contains filtered or unexported fields
}
func NewExpenseService ¶
func NewExpenseService(filepath string) *ExpenseTracker
constructor that initializes the ExpenseTracker service, its sets the file path used to save the expense data
func (*ExpenseTracker) CreateExpense ¶
func (s *ExpenseTracker) CreateExpense(description string, amount float64, date string, category string) (models.Expense, error)
function to create a new expense First verifies the date is correct, loads existing expenses from the root file, Creates a new expense object, and finally call SaveExpenses to save it to the file
func (*ExpenseTracker) DeleteExpense ¶
func (s *ExpenseTracker) DeleteExpense(id int) error
function to remove an expense Loads existing expenses, checks if the expense exists, and if it doesn't, displays an error message. If the expense exists, it removes the expense and saves the updated expense data.
func (*ExpenseTracker) ExportExpense ¶
func (s *ExpenseTracker) ExportExpense(typeExport string) error
Exports data to a file. Only two formats are supported: JSON or CSV.
func (*ExpenseTracker) GetSummaryExpense ¶
func (s *ExpenseTracker) GetSummaryExpense(month int, category string) (float64, error)
/ function to get the summary of all expenses,
func (*ExpenseTracker) LoadExpenses ¶
func (s *ExpenseTracker) LoadExpenses() ([]models.Expense, error)
Retrieves the summary of all expenses, optionally filtered by month and category. If the month is -1, all expenses are included regardless of the month.
func (*ExpenseTracker) LoadExpensesByCategory ¶
func (s *ExpenseTracker) LoadExpensesByCategory(category string) ([]models.Expense, error)
Loads all expenses and filters them by the specified category. If no category is provided, all expenses are returned.
func (*ExpenseTracker) SaveExpenses ¶
func (s *ExpenseTracker) SaveExpenses(expenses []models.Expense) error
Saves the updated list of expenses to the file specified by the file path.
func (*ExpenseTracker) UpdateExpense ¶
func (s *ExpenseTracker) UpdateExpense(id int, description string, amount float64, date string, category string) error
Updates an existing expense with the given ID. It checks if the expense exists, validates the provided date, and then updates the expense details (amount, category, date, description). Finally, it saves the updated expenses to the file.