product_group_controller.go 3.0 KB
package controllers

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

type ProductGroupController struct {
	beego.BaseController
}

func (controller *ProductGroupController) CreateProductGroup() {
	productGroupService := service.NewProductGroupService(nil)
	createProductGroupCommand := &command.CreateProductGroupCommand{}
	controller.Unmarshal(createProductGroupCommand)
	data, err := productGroupService.CreateProductGroup(ParseOperateInfo(controller.BaseController), createProductGroupCommand)
	controller.Response(data, err)
}

func (controller *ProductGroupController) UpdateProductGroup() {
	productGroupService := service.NewProductGroupService(nil)
	updateProductGroupCommand := &command.UpdateProductGroupCommand{}
	controller.Unmarshal(updateProductGroupCommand)
	productGroupId, _ := controller.GetInt(":productGroupId")
	updateProductGroupCommand.ProductGroupId = productGroupId
	data, err := productGroupService.UpdateProductGroup(updateProductGroupCommand)
	controller.Response(data, err)
}

func (controller *ProductGroupController) GetProductGroup() {
	productGroupService := service.NewProductGroupService(nil)
	getProductGroupQuery := &query.GetProductGroupQuery{}
	productGroupId, _ := controller.GetInt(":productGroupId")
	getProductGroupQuery.ProductGroupId = productGroupId
	data, err := productGroupService.GetProductGroup(getProductGroupQuery)
	controller.Response(data, err)
}

func (controller *ProductGroupController) RemoveProductGroup() {
	productGroupService := service.NewProductGroupService(nil)
	removeProductGroupCommand := &command.RemoveProductGroupCommand{}
	controller.Unmarshal(removeProductGroupCommand)
	productGroupId, _ := controller.GetInt(":productGroupId")
	removeProductGroupCommand.ProductGroupId = productGroupId
	data, err := productGroupService.RemoveProductGroup(removeProductGroupCommand)
	controller.Response(data, err)
}

func (controller *ProductGroupController) ListProductGroup() {
	productGroupService := service.NewProductGroupService(nil)
	listProductGroupQuery := &query.ListProductGroupQuery{}
	offset, _ := controller.GetInt("offset")
	listProductGroupQuery.Offset = offset
	limit, _ := controller.GetInt("limit")
	listProductGroupQuery.Limit = limit
	data, err := productGroupService.ListProductGroup(listProductGroupQuery)
	controller.Response(data, err)
}

func (controller *ProductGroupController) SearchProductGroup() {
	productGroupService := service.NewProductGroupService(nil)
	listProductGroupQuery := &query.SearchProductGroupQuery{}
	controller.Unmarshal(listProductGroupQuery)
	total, data, err := productGroupService.SearchProductGroup(ParseOperateInfo(controller.BaseController), listProductGroupQuery)
	ResponseGrid(controller.BaseController, total, data, err)
}