product_section_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/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{}
	Must(controller.Unmarshal(createProductSectionCommand))
	data, err := productSectionService.CreateProductSection(createProductSectionCommand)
	controller.Response(data, err)
}

func (controller *ProductSectionController) UpdateProductSection() {
	productSectionService := service.NewProductSectionService(nil)
	updateProductSectionCommand := &command.UpdateProductSectionCommand{}
	Must(controller.Unmarshal(updateProductSectionCommand))
	sectionId, _ := controller.GetInt(":sectionId")
	lineId, _ := controller.GetInt("lineId")
	workshopId, _ := controller.GetInt("workshopId")
	updateProductSectionCommand.SectionId = sectionId
	updateProductSectionCommand.WorkshopId = workshopId
	updateProductSectionCommand.LineId = lineId
	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
	lineId, _ := controller.GetInt("lineId")
	workshopId, _ := controller.GetInt("workshopId")
	removeProductSectionCommand.LineId = lineId
	removeProductSectionCommand.WorkshopId = workshopId
	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)
}