product_line_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/productLine/command"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productLine/query"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productLine/service"
)

type ProductLineController struct {
	beego.BaseController
}

func (controller *ProductLineController) CreateProductLine() {
	productLineService := service.NewProductLineService(nil)
	createProductLineCommand := &command.CreateProductLineCommand{}
	Must(controller.Unmarshal(createProductLineCommand))
	data, err := productLineService.CreateProductLine(createProductLineCommand)
	controller.Response(data, err)
}

func (controller *ProductLineController) UpdateProductLine() {
	productLineService := service.NewProductLineService(nil)
	updateProductLineCommand := &command.UpdateProductLineCommand{}
	Must(controller.Unmarshal(updateProductLineCommand))
	lineId, _ := controller.GetInt(":lineId")
	workshopId, _ := controller.GetInt("workshopId")
	updateProductLineCommand.LineId = lineId
	updateProductLineCommand.WorkshopId = workshopId
	data, err := productLineService.UpdateProductLine(updateProductLineCommand)
	controller.Response(data, err)
}

func (controller *ProductLineController) GetProductLine() {
	productLineService := service.NewProductLineService(nil)
	getProductLineQuery := &query.GetProductLineQuery{}
	lineId, _ := controller.GetInt(":lineId")
	getProductLineQuery.LineId = lineId
	data, err := productLineService.GetProductLine(getProductLineQuery)
	controller.Response(data, err)
}

func (controller *ProductLineController) RemoveProductLine() {
	productLineService := service.NewProductLineService(nil)
	removeProductLineCommand := &command.RemoveProductLineCommand{}
	//controller.Unmarshal(removeProductLineCommand)
	lineId, _ := controller.GetInt(":lineId")
	workshopId, _ := controller.GetInt("workshopId")
	removeProductLineCommand.LineId = lineId
	removeProductLineCommand.WorkshopId = workshopId
	data, err := productLineService.RemoveProductLine(removeProductLineCommand)
	controller.Response(data, err)
}

func (controller *ProductLineController) ListProductLine() {
	productLineService := service.NewProductLineService(nil)
	listProductLineQuery := &query.ListProductLineQuery{}
	offset, _ := controller.GetInt("offset")
	listProductLineQuery.Offset = offset
	limit, _ := controller.GetInt("limit")
	listProductLineQuery.Limit = limit
	data, err := productLineService.ListProductLine(listProductLineQuery)
	controller.Response(data, err)
}