product_group_controller.go 2.5 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(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)
}