Files
controle-de-estoque-cli/controller/controller.go
T

40 lines
795 B
Go
Raw Normal View History

package controller
import (
"controle-de-estoque/model"
"controle-de-estoque/view"
)
type Controller struct {
inventory *model.Inventory
}
func New(inventory *model.Inventory) *Controller {
return &Controller{inventory: inventory}
}
2026-07-14 22:11:22 -03:00
func (c *Controller) Execute() {
for {
view.ShowMenu()
input, err := view.ReadMenuInput()
2026-07-14 22:11:22 -03:00
if err != nil {
view.ShowError(err)
break
}
switch input {
case "1", "adicionar":
productInput := view.ReadProdutoInput()
p := c.inventory.AdicionarProduto(productInput)
view.ShowMessage("Produto criado com ID %d: %s\n", []any{p.ID, p.Name})
2026-07-14 22:37:11 -03:00
case "2", "listar":
products := c.inventory.ListarProdutos()
view.ShowAllProducts(products)
default:
view.ShowMessage("Obrigado por utilizar o programa!", nil)
return
2026-07-14 22:11:22 -03:00
}
}
}