cooperation_mode_controller.go 4.5 KB
package web_client

import (
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/cooperationMode/command"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/cooperationMode/query"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/cooperationMode/service"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
)

type CooperationModeController struct {
	baseController
}

func (controller *CooperationModeController) CreateCooperationMode() {
	cooperationModeService := service.NewCooperationModeService(nil)
	createCooperationModeCommand := &command.CreateCooperationModeCommand{}
	err := controller.Unmarshal(createCooperationModeCommand)
	if err != nil {
		log.Logger.Debug("json err:" + err.Error())
		controller.Response(nil, err)
		return
	}
	createCooperationModeCommand.Operator = controller.GetOperator()
	data, err := cooperationModeService.CreateCooperationMode(createCooperationModeCommand)
	controller.Response(data, err)
}

func (controller *CooperationModeController) UpdateCooperationMode() {
	cooperationModeService := service.NewCooperationModeService(nil)
	updateCooperationModeCommand := &command.UpdateCooperationModeCommand{}
	err := controller.Unmarshal(updateCooperationModeCommand)
	if err != nil {
		log.Logger.Debug("json err:" + err.Error())
		controller.Response(nil, err)
		return
	}
	modeId, _ := controller.GetInt(":modeId")
	updateCooperationModeCommand.Operator = controller.GetOperator()
	updateCooperationModeCommand.CooperationModeId = modeId
	data, err := cooperationModeService.UpdateCooperationMode(updateCooperationModeCommand)
	controller.Response(data, err)
}

func (controller *CooperationModeController) GetCooperationMode() {
	cooperationModeService := service.NewCooperationModeService(nil)
	getCooperationModeQuery := &query.GetCooperationModeQuery{}
	modeId, _ := controller.GetInt(":modeId")
	getCooperationModeQuery.CooperationModeId = modeId
	getCooperationModeQuery.Operator = controller.GetOperator()
	data, err := cooperationModeService.GetCooperationMode(getCooperationModeQuery)
	controller.Response(data, err)
}

func (controller *CooperationModeController) RemoveCooperationMode() {
	cooperationModeService := service.NewCooperationModeService(nil)
	removeCooperationModeCommand := &command.RemoveCooperationModeCommand{}
	err := controller.Unmarshal(removeCooperationModeCommand)
	if err != nil {
		log.Logger.Debug("json err:" + err.Error())
		controller.Response(nil, err)
		return
	}
	removeCooperationModeCommand.Operator = controller.GetOperator()

	data, err := cooperationModeService.RemoveCooperationMode(removeCooperationModeCommand)
	controller.Response(data, err)
}

func (controller *CooperationModeController) SearchCooperationMode() {
	cooperationModeService := service.NewCooperationModeService(nil)
	listCooperationModeQuery := &query.ListCooperationModeQuery{}
	err := controller.Unmarshal(listCooperationModeQuery)
	if err != nil {
		log.Logger.Debug("json err:" + err.Error())
		controller.Response(nil, err)
		return
	}
	listCooperationModeQuery.Operator = controller.GetOperator()
	cnt, data, err := cooperationModeService.ListCooperationMode(listCooperationModeQuery)
	controller.ReturnPageListData(cnt, data, err, listCooperationModeQuery.PageNumber)
}

func (controller *CooperationModeController) ListCooperationMode() {
	cooperationModeService := service.NewCooperationModeService(nil)
	listCooperationModeQuery := &query.ListCooperationModeQuery{}
	// err := controller.Unmarshal(listCooperationModeQuery)
	// if err != nil {
	// 	log.Logger.Debug("json err:" + err.Error())
	// 	controller.Response(nil, err)
	// 	return
	// }
	listCooperationModeQuery.Operator = controller.GetOperator()
	listCooperationModeQuery.PageNumber = 1
	listCooperationModeQuery.PageSize = 999
	cnt, data, err := cooperationModeService.CooperationModeSelector(listCooperationModeQuery)
	controller.ReturnListData(cnt, data, err)
}

func (controller *CooperationModeController) EnableCooperationMode() {
	cooperationModeService := service.NewCooperationModeService(nil)
	removeCooperationModeCommand := &command.OperateCooperationModeCommand{}
	err := controller.Unmarshal(removeCooperationModeCommand)
	if err != nil {
		log.Logger.Debug("json err:" + err.Error())
		controller.Response(nil, err)
		return
	}
	removeCooperationModeCommand.Operator = controller.GetOperator()

	data, err := cooperationModeService.EnableCooperationMode(removeCooperationModeCommand)
	controller.Response(data, err)
}