product_section_controller.go 2.6 KB
package controllers

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

type ProductSectionController struct {
	beego.BaseController
}

func (controller *ProductSectionController) CreateProductSection() {
	productSectionService := service.NewProductSectionService(nil)
	createProductSectionCommand := &command.CreateProductSectionCommand{}
	controller.Unmarshal(createProductSectionCommand)
	data, err := productSectionService.CreateProductSection(createProductSectionCommand)
	controller.Response(data, err)
}

func (controller *ProductSectionController) UpdateProductSection() {
	productSectionService := service.NewProductSectionService(nil)
	updateProductSectionCommand := &command.UpdateProductSectionCommand{}
	controller.Unmarshal(updateProductSectionCommand)
	sectionId, _ := controller.GetInt(":sectionId")
	updateProductSectionCommand.SectionId = sectionId
	data, err := productSectionService.UpdateProductSection(updateProductSectionCommand)
	controller.Response(data, err)
}

func (controller *ProductSectionController) GetProductSection() {
	productSectionService := service.NewProductSectionService(nil)
	getProductSectionQuery := &query.GetProductSectionQuery{}
	sectionId, _ := controller.GetInt(":sectionId")
	getProductSectionQuery.SectionId = sectionId
	data, err := productSectionService.GetProductSection(getProductSectionQuery)
	controller.Response(data, err)
}

func (controller *ProductSectionController) RemoveProductSection() {
	productSectionService := service.NewProductSectionService(nil)
	removeProductSectionCommand := &command.RemoveProductSectionCommand{}
	controller.Unmarshal(removeProductSectionCommand)
	sectionId, _ := controller.GetInt(":sectionId")
	removeProductSectionCommand.SectionId = sectionId
	data, err := productSectionService.RemoveProductSection(removeProductSectionCommand)
	controller.Response(data, err)
}

func (controller *ProductSectionController) ListProductSection() {
	productSectionService := service.NewProductSectionService(nil)
	listProductSectionQuery := &query.ListProductSectionQuery{}
	offset, _ := controller.GetInt("offset")
	listProductSectionQuery.Offset = offset
	limit, _ := controller.GetInt("limit")
	listProductSectionQuery.Limit = limit
	data, err := productSectionService.ListProductSection(listProductSectionQuery)
	controller.Response(data, err)
}