adding revenue handlers and shell
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user