services

package
v0.0.0-...-9e51f3e Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Any

func Any(expenses []models.Expense, condition func(models.Expense) bool) bool

Return true if expense exist in the slice.

func CopyFile

func CopyFile(filePath string) error

function to copy json files

func JSONToCSV

func JSONToCSV(filePath string) error

Creates a new CSV file and exports the expenses from the original file into the new CSV file.

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.

Jump to

Keyboard shortcuts

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