add revenue now workd through shell command

This commit is contained in:
samantha42
2026-03-24 21:31:01 +01:00
parent 7e2c332e60
commit 63be7b9282
13 changed files with 200 additions and 78 deletions

View File

@@ -1,6 +1,7 @@
package shell
import (
"Portifolio/internal/database"
"Portifolio/internal/model"
"Portifolio/internal/service"
"bufio"
@@ -68,10 +69,13 @@ func ListCompanies(db *sql.DB) {
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
currency, err := database.GetCurrencyByID(db, c.CurrencyID)
if err != nil {
fmt.Println("No currency by id.")
return
}
fmt.Printf(" %-5d %-20s %-10s %-15.2f %d\n",
c.ID, c.Name, currency, c.Price, c.SharesOutstanding)
}

View File

@@ -1,6 +1,7 @@
package shell
import (
"Portifolio/internal/database"
"Portifolio/internal/model"
"Portifolio/internal/service"
"bufio"
@@ -67,6 +68,12 @@ func AddRevenue(scanner *bufio.Scanner, db *sql.DB) {
fmt.Println(" ✗", err)
return
}
// checking if company exits
_, err = database.GetCompanyByID(db, companyID)
if err != nil {
fmt.Println("No company by that id:", err)
return
}
currencyID, err := promptInt(scanner, " Currency ID: ")
if err != nil {
fmt.Println(" ✗", err)