product_material_controller.go 2.8 KB
package controllers

import (
	"github.com/linmadan/egglib-go/web/beego"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productMaterial/command"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productMaterial/query"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productMaterial/service"
)

type ProductMaterialController struct {
	beego.BaseController
}

func (controller *ProductMaterialController) CreateProductMaterial() {
	productMaterialService := service.NewProductMaterialService(nil)
	cmd := &command.CreateProductMaterialCommand{}
	controller.Unmarshal(cmd)
	operateInfo := ParseOperateInfo(controller.BaseController)
	cmd.CompanyId = operateInfo.CompanyId
	cmd.OrgId = operateInfo.OrgId
	data, err := productMaterialService.CreateProductMaterial(operateInfo, cmd)
	controller.Response(data, err)
}

func (controller *ProductMaterialController) UpdateProductMaterial() {
	productMaterialService := service.NewProductMaterialService(nil)
	updateProductMaterialCommand := &command.UpdateProductMaterialCommand{}
	controller.Unmarshal(updateProductMaterialCommand)
	productMaterialId, _ := controller.GetInt(":productMaterialId")
	updateProductMaterialCommand.ProductMaterialId = productMaterialId
	data, err := productMaterialService.UpdateProductMaterial(updateProductMaterialCommand)
	controller.Response(data, err)
}

func (controller *ProductMaterialController) GetProductMaterial() {
	productMaterialService := service.NewProductMaterialService(nil)
	getProductMaterialQuery := &query.GetProductMaterialQuery{}
	productMaterialId, _ := controller.GetInt(":productMaterialId")
	getProductMaterialQuery.ProductMaterialId = productMaterialId
	data, err := productMaterialService.GetProductMaterial(getProductMaterialQuery)
	controller.Response(data, err)
}

func (controller *ProductMaterialController) RemoveProductMaterial() {
	productMaterialService := service.NewProductMaterialService(nil)
	removeProductMaterialCommand := &command.RemoveProductMaterialCommand{}
	controller.Unmarshal(removeProductMaterialCommand)
	productMaterialId, _ := controller.GetInt(":productMaterialId")
	removeProductMaterialCommand.ProductMaterialId = productMaterialId
	data, err := productMaterialService.RemoveProductMaterial(removeProductMaterialCommand)
	controller.Response(data, err)
}

func (controller *ProductMaterialController) ListProductMaterial() {
	productMaterialService := service.NewProductMaterialService(nil)
	listProductMaterialQuery := &query.ListProductMaterialQuery{}
	offset, _ := controller.GetInt("offset")
	listProductMaterialQuery.Offset = offset
	limit, _ := controller.GetInt("limit")
	listProductMaterialQuery.Limit = limit
	data, err := productMaterialService.ListProductMaterial(listProductMaterialQuery)
	controller.Response(data, err)
}