adding revenue handlers and shell

This commit is contained in:
samantha42
2026-03-24 12:09:19 +01:00
parent 33b100f325
commit 1a9fe3adc7
13 changed files with 688 additions and 37 deletions

View File

@@ -52,3 +52,27 @@ func AddCompany(scanner *bufio.Scanner, db *sql.DB) {
}
fmt.Printf(" ✓ Company '%s' added.\n", input.Name)
}
func ListCompanies(db *sql.DB) {
companies, err := service.GetAllCompanies(db)
if err != nil {
fmt.Println(" ✗ Error:", err)
return
}
if len(companies) == 0 {
fmt.Println(" No companies found.")
return
}
fmt.Printf("\n %-5s %-20s %-10s %-15s %s\n", "ID", "NAME", "CURRENCY", "PRICE", "SHARES")
fmt.Println(" " + strings.Repeat("-", 60))
for _, c := range companies {
currency := "N/A"
if c.Currency != nil {
currency = c.Currency.Code
}
fmt.Printf(" %-5d %-20s %-10s %-15.2f %d\n",
c.ID, c.Name, currency, c.Price, c.SharesOutstanding)
}
}