feat(list): added list to show all expenses

This commit is contained in:
DarthMooMancer committed 2026-11-13 12:13:52 -05:00
1 parent 0eb44d4bc4
commit 28e836af23
1 file changed
+18 -11
+18 -11
View File
@@ -3,6 +3,8 @@ package main
import (
"encoding/json"
"errors"
"fmt"
"math"
"os"
"strconv"
"time"
@@ -72,12 +74,17 @@ $ expense-tracker list
# 1 2024-08-06 Lunch $20
# 2 2024-08-06 Dinner $10
*/
func list() {
/*
1. Load tasks
2. Print a single newline statement for section headers
3. Loop over tasks and print id, date, descript, amount
*/
func list(fileName string) error {
fmt.Println("ID Date Description Amount")
exp, err := loadExpenses(fileName)
if err != nil {
panic(err)
}
for _, i := range exp {
y, m, d := i.Date.Date()
fmt.Printf("%d %d-%s-%d %s $%.2f\n", i.Id, y, m, d, i.Desc, math.Round(float64(i.Amount)*100)/100)
}
return nil
}
/*
@@ -187,13 +194,13 @@ func main() {
}
}
add(fileName, desc, amount)
} else if args[0] == "list" {
err := list(fileName)
if err != nil {
panic(err)
}
}
// Send expenses slice to functions instead of making them load each time because io is slower than memory management
// fmt.Println("Hello World")
// add(&exp, "test", 10)
// for _, i := range exp {
// y, m, d := i.Date.Date()
// fmt.Printf("[%d], %s: %.2f at %d-%s-%d", i.Id, i.Desc, math.Round(float64(i.Amount)*100)/100, y, m, d)
// }
}