feat: criando a view do menu e as regras de cadastro e listagem de produtos
This commit is contained in:
@@ -0,0 +1,21 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"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) CapturarComando(scanner *bufio.Scanner) {
|
||||||
|
view.ExibirMenu()
|
||||||
|
|
||||||
|
// scanner.Scan()
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,16 @@
|
|||||||
// main.go
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
func main() {
|
import (
|
||||||
|
"bufio"
|
||||||
|
"controle-de-estoque/controller"
|
||||||
|
"controle-de-estoque/model"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
estoque := model.NewInventory()
|
||||||
|
controller := controller.New(estoque)
|
||||||
|
scanner := bufio.NewScanner(os.Stdin)
|
||||||
|
|
||||||
|
controller.CapturarComando(scanner)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
type Product struct {
|
||||||
|
ID int
|
||||||
|
Name string
|
||||||
|
Category string
|
||||||
|
Price float64
|
||||||
|
Quantity int
|
||||||
|
}
|
||||||
|
|
||||||
|
type ProductInput struct {
|
||||||
|
Name string
|
||||||
|
Category string
|
||||||
|
Price float64
|
||||||
|
Quantity int
|
||||||
|
}
|
||||||
|
|
||||||
|
type Inventory struct {
|
||||||
|
products []Product
|
||||||
|
nextID int
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewInventory() *Inventory {
|
||||||
|
return &Inventory{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *Inventory) AdicionarProduto(i *ProductInput) Product {
|
||||||
|
e.nextID += 1
|
||||||
|
|
||||||
|
product := Product{
|
||||||
|
ID: e.nextID,
|
||||||
|
Name: i.Name,
|
||||||
|
Category: i.Category,
|
||||||
|
Price: i.Price,
|
||||||
|
Quantity: i.Quantity,
|
||||||
|
}
|
||||||
|
|
||||||
|
e.products = append(e.products, product)
|
||||||
|
|
||||||
|
return product
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *Inventory) ListarProduto() []Product {
|
||||||
|
return e.products
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *Inventory) AtualizarProduto() {}
|
||||||
|
|
||||||
|
func (e *Inventory) DeletarProduto() {}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package view
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func ExibirMenu() {
|
||||||
|
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
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user