2026-07-14 20:16:10 -03:00
|
|
|
package view
|
|
|
|
|
|
2026-07-14 22:11:22 -03:00
|
|
|
import (
|
|
|
|
|
"bufio"
|
|
|
|
|
"controle-de-estoque/model"
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
2026-07-14 20:16:10 -03:00
|
|
|
|
2026-07-14 22:11:22 -03:00
|
|
|
func ShowMenu() {
|
2026-07-14 20:16:10 -03:00
|
|
|
fmt.Print(`
|
|
|
|
|
============ CONTROLE DE ESTOQUE ==============
|
|
|
|
|
ESCOLHA UMA DAS OPÇÕES:
|
|
|
|
|
1 / adicionar - Adiciona o produto no estoque
|
|
|
|
|
2 / listar - Lista todos os produtos do estoque
|
|
|
|
|
3 / atualizar - Atualiza um produto do estoque
|
|
|
|
|
4 / deletar - Deleta um produto do estoque
|
|
|
|
|
0 / sair - Sair do programa
|
2026-07-14 22:37:11 -03:00
|
|
|
=================================================
|
2026-07-14 20:16:10 -03:00
|
|
|
`)
|
|
|
|
|
}
|
2026-07-14 22:11:22 -03:00
|
|
|
|
|
|
|
|
func ShowError(err error) {
|
|
|
|
|
fmt.Println("Error: ", err)
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-14 22:37:11 -03:00
|
|
|
func ShowMessage(msg string, args []any) {
|
|
|
|
|
if args == nil {
|
|
|
|
|
fmt.Println(msg)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt.Printf(msg, args...)
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-14 22:11:22 -03:00
|
|
|
func ReadMenuInput() (string, error) {
|
|
|
|
|
reader := bufio.NewReader(os.Stdin)
|
|
|
|
|
input, err := reader.ReadString('\n')
|
|
|
|
|
input = strings.TrimSpace(input)
|
|
|
|
|
|
|
|
|
|
if err != nil || input == "" {
|
|
|
|
|
return input, errors.New("Opção Inválida!")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return input, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ReadProdutoInput() *model.ProductInput {
|
|
|
|
|
reader := bufio.NewReader(os.Stdin)
|
|
|
|
|
|
|
|
|
|
fmt.Print("Nome do produto: ")
|
|
|
|
|
name, _ := reader.ReadString('\n')
|
|
|
|
|
|
|
|
|
|
fmt.Print("Categoria do produto: ")
|
|
|
|
|
category, _ := reader.ReadString('\n')
|
|
|
|
|
|
|
|
|
|
fmt.Print("Preço: ")
|
|
|
|
|
precoStr, _ := reader.ReadString('\n')
|
|
|
|
|
price, _ := strconv.ParseFloat(strings.TrimSpace(precoStr), 64)
|
|
|
|
|
|
|
|
|
|
fmt.Print("Quantidade: ")
|
|
|
|
|
qtyStr, _ := reader.ReadString('\n')
|
|
|
|
|
quantity, _ := strconv.Atoi(strings.TrimSpace(qtyStr))
|
|
|
|
|
|
|
|
|
|
return &model.ProductInput{
|
2026-07-14 22:37:11 -03:00
|
|
|
Name: strings.TrimSpace(name),
|
|
|
|
|
Category: strings.TrimSpace(category),
|
2026-07-14 22:11:22 -03:00
|
|
|
Price: price,
|
|
|
|
|
Quantity: quantity,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-14 22:37:11 -03:00
|
|
|
func ShowAllProducts(products []model.Product) {
|
|
|
|
|
for _, p := range products {
|
|
|
|
|
id := p.ID
|
|
|
|
|
name := p.Name
|
|
|
|
|
category := p.Category
|
|
|
|
|
price := p.Price
|
|
|
|
|
quantity := p.Quantity
|
2026-07-14 22:11:22 -03:00
|
|
|
|
2026-07-14 22:37:11 -03:00
|
|
|
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)
|
|
|
|
|
}
|
2026-07-14 22:11:22 -03:00
|
|
|
}
|