40 lines
795 B
Go
40 lines
795 B
Go
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}
|
|
}
|
|
|
|
func (c *Controller) Execute() {
|
|
for {
|
|
view.ShowMenu()
|
|
input, err := view.ReadMenuInput()
|
|
|
|
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})
|
|
case "2", "listar":
|
|
products := c.inventory.ListarProdutos()
|
|
view.ShowAllProducts(products)
|
|
default:
|
|
view.ShowMessage("Obrigado por utilizar o programa!", nil)
|
|
return
|
|
}
|
|
}
|
|
}
|