basic internal structure
This commit is contained in:
44
internal/shell/currency.go
Normal file
44
internal/shell/currency.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package shell
|
||||
|
||||
import (
|
||||
"Portifolio/internal/model"
|
||||
"Portifolio/internal/service"
|
||||
"bufio"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
func AddCurrency(scanner *bufio.Scanner, db *sql.DB) {
|
||||
input := model.CurrencyInput{}
|
||||
|
||||
fmt.Print(" Code (e.g. DKK): ")
|
||||
scanner.Scan()
|
||||
input.Code = strings.ToUpper(strings.TrimSpace(scanner.Text()))
|
||||
|
||||
fmt.Print(" Name (e.g. Danish Krone): ")
|
||||
scanner.Scan()
|
||||
input.Name = strings.TrimSpace(scanner.Text())
|
||||
|
||||
id, err := service.InsertCurrency(db, input)
|
||||
if err != nil {
|
||||
fmt.Println(" ✗ Error:", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf(" ✓ Currency '%s' (%s) added with ID %d\n", input.Name, input.Code, id)
|
||||
}
|
||||
|
||||
func ListCurrencies(db *sql.DB) {
|
||||
currencies, err := service.GetAllCurrencies(db)
|
||||
if err != nil {
|
||||
fmt.Println(" ✗ Error:", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf(" %-5s %-6s %s\n", "ID", "CODE", "NAME")
|
||||
fmt.Println(" " + strings.Repeat("-", 30))
|
||||
for _, c := range currencies {
|
||||
fmt.Printf(" %-5d %-6s %s\n", c.ID, c.Code, c.Name)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user