feat: listando os produtos
This commit is contained in:
+29
-8
@@ -19,6 +19,7 @@ func ShowMenu() {
|
||||
3 / atualizar - Atualiza um produto do estoque
|
||||
4 / deletar - Deleta um produto do estoque
|
||||
0 / sair - Sair do programa
|
||||
=================================================
|
||||
`)
|
||||
}
|
||||
|
||||
@@ -26,6 +27,15 @@ func ShowError(err error) {
|
||||
fmt.Println("Error: ", err)
|
||||
}
|
||||
|
||||
func ShowMessage(msg string, args []any) {
|
||||
if args == nil {
|
||||
fmt.Println(msg)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf(msg, args...)
|
||||
}
|
||||
|
||||
func ReadMenuInput() (string, error) {
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
input, err := reader.ReadString('\n')
|
||||
@@ -56,18 +66,29 @@ func ReadProdutoInput() *model.ProductInput {
|
||||
quantity, _ := strconv.Atoi(strings.TrimSpace(qtyStr))
|
||||
|
||||
return &model.ProductInput{
|
||||
Name: name,
|
||||
Category: category,
|
||||
Name: strings.TrimSpace(name),
|
||||
Category: strings.TrimSpace(category),
|
||||
Price: price,
|
||||
Quantity: quantity,
|
||||
}
|
||||
}
|
||||
|
||||
func ShowMessage(msg string, args []any) {
|
||||
if args == nil {
|
||||
fmt.Println(msg)
|
||||
return
|
||||
}
|
||||
func ShowAllProducts(products []model.Product) {
|
||||
for _, p := range products {
|
||||
id := p.ID
|
||||
name := p.Name
|
||||
category := p.Category
|
||||
price := p.Price
|
||||
quantity := p.Quantity
|
||||
|
||||
fmt.Printf(msg, args...)
|
||||
fmt.Printf(
|
||||
"==============================================="+"\n"+
|
||||
"PRODUTO: %d"+"\n"+
|
||||
"NOME: %s"+"\n"+
|
||||
"CATEGORIA: %s"+"\n"+
|
||||
"PREÇO: %.2f"+"\n"+
|
||||
"QUANTIDADE: %d"+"\n"+
|
||||
"==============================================="+"\n",
|
||||
id, name, category, price, quantity)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user