feat: deletar produtos
This commit is contained in:
+10
-1
@@ -29,6 +29,7 @@ type Inventory struct {
|
||||
products map[ProductID]Product
|
||||
}
|
||||
|
||||
// função auxiliar para criar a instância do objeto Inventory
|
||||
func NewInventory() *Inventory {
|
||||
return &Inventory{products: make(map[ProductID]Product)}
|
||||
}
|
||||
@@ -86,4 +87,12 @@ func (e *Inventory) UpdateProduct(id ProductID, field, value string) (*Product,
|
||||
return &product, nil
|
||||
}
|
||||
|
||||
func (e *Inventory) DeleteProduct() {}
|
||||
func (e *Inventory) DeleteProduct(id ProductID) error {
|
||||
if _, ok := e.products[id]; !ok {
|
||||
return errors.New("Produto não encontrado")
|
||||
}
|
||||
|
||||
delete(e.products, id)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user