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

50
main.go
View File

@@ -33,11 +33,19 @@ func main() {
fmt.Println("Connected to SQLite database")
http.HandleFunc("/health", handlers.HealthHandler(db))
// Company
http.HandleFunc("POST /add/company", handlers.AddCompanyHandler(db))
/*
http.HandleFunc("GET /companies", handlers.AddCompanyHandler(db))
http.HandleFunc("GET /currencies", handlers.AddCompanyHandler(db))
*/
http.HandleFunc("GET /companies", handlers.GetCompaniesHandler(db))
// Currency
http.HandleFunc("GET /currencies", handlers.GetCurrenciesHandler(db))
// Revenue
http.HandleFunc("POST /add/revenue/report", handlers.AddRevenueReportHandler(db))
http.HandleFunc("POST /add/revenue/entry", handlers.AddRevenueEntryHandler(db))
http.HandleFunc("GET /revenue/report", handlers.GetRevenueReportHandler(db))
http.HandleFunc("GET /revenue/sum", handlers.GetRevenueSumHandler(db))
fmt.Println("Server running on :8080")
go func() {
@@ -49,7 +57,7 @@ func main() {
func runShell(db *sql.DB) {
scanner := bufio.NewScanner(os.Stdin)
fmt.Println("\nShell ready. Commands: add-company, help, exit")
fmt.Println("\nShell ready. Type 'help' for commands.")
for {
fmt.Print("> ")
@@ -63,20 +71,40 @@ func runShell(db *sql.DB) {
}
switch parts[0] {
// Company
case "add-company":
shell.AddCompany(scanner, db)
case "list-companies":
shell.ListCompanies(db)
// Currency
case "add-currency":
shell.AddCurrency(scanner, db)
case "list-currency":
shell.ListCurrencies(db)
case "help":
fmt.Println("Commands:")
fmt.Println(" add-company - add a new company interactively")
fmt.Println(" add-currency - add a new currency interactively")
fmt.Println(" list-currency - lists all currencies")
// Revenue
case "add-revenue":
shell.AddRevenue(scanner, db)
case "list-revenue":
shell.ListRevenue(scanner, db)
case "sum-revenue":
shell.SumRevenue(scanner, db)
fmt.Println(" exit - quit")
case "help":
fmt.Println("\nCommands:")
fmt.Println(" --- Company ---")
fmt.Println(" add-company add a new company")
fmt.Println(" list-companies list all companies")
fmt.Println(" --- Currency ---")
fmt.Println(" add-currency add a new currency")
fmt.Println(" list-currency list all currencies")
fmt.Println(" --- Revenue ---")
fmt.Println(" add-revenue add a revenue entry interactively")
fmt.Println(" list-revenue list revenue for a company/period")
fmt.Println(" sum-revenue sum revenue across periods")
fmt.Println(" --- Other ---")
fmt.Println(" exit quit")
case "exit":
fmt.Println("Bye!")