unit_conversion_controller.go 2.7 KB
package controllers

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

type UnitConversionController struct {
	beego.BaseController
}

func (controller *UnitConversionController) CreateUnitConversion() {
	unitConversionService := service.NewUnitConversionService(nil)
	createUnitConversionCommand := &command.CreateUnitConversionCommand{}
	controller.Unmarshal(createUnitConversionCommand)
	data, err := unitConversionService.CreateUnitConversion(createUnitConversionCommand)
	controller.Response(data, err)
}

func (controller *UnitConversionController) UpdateUnitConversion() {
	unitConversionService := service.NewUnitConversionService(nil)
	updateUnitConversionCommand := &command.UpdateUnitConversionCommand{}
	controller.Unmarshal(updateUnitConversionCommand)
	unitConversionId, _ := controller.GetInt(":unitConversionId")
	updateUnitConversionCommand.UnitConversionId = unitConversionId
	data, err := unitConversionService.UpdateUnitConversion(updateUnitConversionCommand)
	controller.Response(data, err)
}

func (controller *UnitConversionController) GetUnitConversion() {
	unitConversionService := service.NewUnitConversionService(nil)
	getUnitConversionQuery := &query.GetUnitConversionQuery{}
	unitConversionId, _ := controller.GetInt(":unitConversionId")
	getUnitConversionQuery.UnitConversionId = unitConversionId
	data, err := unitConversionService.GetUnitConversion(getUnitConversionQuery)
	controller.Response(data, err)
}

func (controller *UnitConversionController) RemoveUnitConversion() {
	unitConversionService := service.NewUnitConversionService(nil)
	removeUnitConversionCommand := &command.RemoveUnitConversionCommand{}
	controller.Unmarshal(removeUnitConversionCommand)
	unitConversionId, _ := controller.GetInt(":unitConversionId")
	removeUnitConversionCommand.UnitConversionId = unitConversionId
	data, err := unitConversionService.RemoveUnitConversion(removeUnitConversionCommand)
	controller.Response(data, err)
}

func (controller *UnitConversionController) ListUnitConversion() {
	unitConversionService := service.NewUnitConversionService(nil)
	listUnitConversionQuery := &query.ListUnitConversionQuery{}
	offset, _ := controller.GetInt("offset")
	listUnitConversionQuery.Offset = offset
	limit, _ := controller.GetInt("limit")
	listUnitConversionQuery.Limit = limit
	data, err := unitConversionService.ListUnitConversion(listUnitConversionQuery)
	controller.Response(data, err)
}