product_line_controller.go 2.4 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{}
	controller.Unmarshal(createProductLineCommand)
	data, err := productLineService.CreateProductLine(createProductLineCommand)
	controller.Response(data, err)
}

func (controller *ProductLineController) UpdateProductLine() {
	productLineService := service.NewProductLineService(nil)
	updateProductLineCommand := &command.UpdateProductLineCommand{}
	controller.Unmarshal(updateProductLineCommand)
	lineId, _ := controller.GetInt(":lineId")
	updateProductLineCommand.LineId = lineId
	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")
	removeProductLineCommand.LineId = lineId
	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)
}