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

type ProductJobController struct {
	beego.BaseController
}

func (controller *ProductJobController) CreateProductJob() {
	productJobService := service.NewProductJobService(nil)
	createProductJobCommand := &command.CreateProductJobCommand{}
	controller.Unmarshal(createProductJobCommand)
	data, err := productJobService.CreateProductJob(createProductJobCommand)
	controller.Response(data, err)
}

func (controller *ProductJobController) UpdateProductJob() {
	productJobService := service.NewProductJobService(nil)
	updateProductJobCommand := &command.UpdateProductJobCommand{}
	controller.Unmarshal(updateProductJobCommand)
	productJobId, _ := controller.GetInt(":productJobId")
	updateProductJobCommand.ProductJobId = productJobId
	data, err := productJobService.UpdateProductJob(updateProductJobCommand)
	controller.Response(data, err)
}

func (controller *ProductJobController) GetProductJob() {
	productJobService := service.NewProductJobService(nil)
	getProductJobQuery := &query.GetProductJobQuery{}
	productJobId, _ := controller.GetInt(":productJobId")
	getProductJobQuery.ProductJobId = productJobId
	data, err := productJobService.GetProductJob(getProductJobQuery)
	controller.Response(data, err)
}

func (controller *ProductJobController) RemoveProductJob() {
	productJobService := service.NewProductJobService(nil)
	removeProductJobCommand := &command.RemoveProductJobCommand{}
	controller.Unmarshal(removeProductJobCommand)
	productJobId, _ := controller.GetInt(":productJobId")
	removeProductJobCommand.ProductJobId = productJobId
	data, err := productJobService.RemoveProductJob(removeProductJobCommand)
	controller.Response(data, err)
}

func (controller *ProductJobController) ListProductJob() {
	productJobService := service.NewProductJobService(nil)
	listProductJobQuery := &query.ListProductJobQuery{}
	offset, _ := controller.GetInt("offset")
	listProductJobQuery.Offset = offset
	limit, _ := controller.GetInt("limit")
	listProductJobQuery.Limit = limit
	data, err := productJobService.ListProductJob(listProductJobQuery)
	controller.Response(data, err)
}