product_controller.go
2.2 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
package controllers
import (
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/product/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/product/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/product/service"
)
type ProductController struct {
beego.BaseController
}
func (controller *ProductController) CreateProduct() {
productService := service.NewProductService(nil)
createProductCommand := &command.CreateProductCommand{}
controller.Unmarshal(createProductCommand)
data, err := productService.CreateProduct(createProductCommand)
controller.Response(data, err)
}
func (controller *ProductController) UpdateProduct() {
productService := service.NewProductService(nil)
updateProductCommand := &command.UpdateProductCommand{}
controller.Unmarshal(updateProductCommand)
productId, _ := controller.GetInt(":productId")
updateProductCommand.ProductId = productId
data, err := productService.UpdateProduct(updateProductCommand)
controller.Response(data, err)
}
func (controller *ProductController) GetProduct() {
productService := service.NewProductService(nil)
getProductQuery := &query.GetProductQuery{}
productId, _ := controller.GetInt(":productId")
getProductQuery.ProductId = productId
data, err := productService.GetProduct(getProductQuery)
controller.Response(data, err)
}
func (controller *ProductController) RemoveProduct() {
productService := service.NewProductService(nil)
removeProductCommand := &command.RemoveProductCommand{}
controller.Unmarshal(removeProductCommand)
productId, _ := controller.GetInt(":productId")
removeProductCommand.ProductId = productId
data, err := productService.RemoveProduct(removeProductCommand)
controller.Response(data, err)
}
func (controller *ProductController) ListProduct() {
productService := service.NewProductService(nil)
listProductQuery := &query.ListProductQuery{}
offset, _ := controller.GetInt("offset")
listProductQuery.Offset = offset
limit, _ := controller.GetInt("limit")
listProductQuery.Limit = limit
data, err := productService.ListProduct(listProductQuery)
controller.Response(data, err)
}