-
Notifications
You must be signed in to change notification settings - Fork 0
/
product.go
48 lines (43 loc) · 1.29 KB
/
product.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package cli
import (
"fmt"
"github.com/vinigracindo/golang-webapp/application"
)
func Run(service application.ProductServiceInterface, action string, productId string, productName string, price float64) (string, error) {
var result = ""
switch action {
case "create":
product, err := service.Create(productName, price)
if err != nil {
return result, err
}
result = fmt.Sprintf("Product ID #%s with the name %s has been created with the price %f and status %s", product.GetID(), product.GetName(), product.GetPrice(), product.GetStatus())
case "enable":
product, err := service.Get(productId)
if err != nil {
return result, err
}
res, err := service.Enable(product)
if err != nil {
return result, err
}
result = fmt.Sprintf("Product %s has been enabled.", res.GetName())
case "disable":
product, err := service.Get(productId)
if err != nil {
return result, err
}
res, err := service.Disable(product)
if err != nil {
return result, err
}
result = fmt.Sprintf("Product %s has been disabled.", res.GetName())
default:
res, err := service.Get(productId)
if err != nil {
return result, err
}
result = fmt.Sprintf("Product ID: %s\nName: %s\nPrice: %f\nStatus: %s", res.GetID(), res.GetName(), res.GetPrice(), res.GetStatus())
}
return result, nil
}