mapping_rule_controller.go 3.3 KB
package controllers

import (
	"github.com/linmadan/egglib-go/web/beego"
	"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/mappingRule/command"
	"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/mappingRule/query"
	"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/mappingRule/service"
)

type MappingRuleController struct {
	beego.BaseController
}

func (controller *MappingRuleController) CreateMappingRule() {
	mappingRuleService := service.NewMappingRuleService(nil)
	createMappingRuleCommand := &command.CreateMappingRuleCommand{}
	controller.Unmarshal(createMappingRuleCommand)
	data, err := mappingRuleService.CreateMappingRule(ParseContext(controller.BaseController), createMappingRuleCommand)
	controller.Response(data, err)
}

func (controller *MappingRuleController) UpdateMappingRule() {
	mappingRuleService := service.NewMappingRuleService(nil)
	updateMappingRuleCommand := &command.UpdateMappingRuleCommand{}
	controller.Unmarshal(updateMappingRuleCommand)
	mappingRuleId, _ := controller.GetInt(":mappingRuleId")
	updateMappingRuleCommand.MappingRuleId = mappingRuleId
	data, err := mappingRuleService.UpdateMappingRule(ParseContext(controller.BaseController), updateMappingRuleCommand)
	controller.Response(data, err)
}

func (controller *MappingRuleController) GetMappingRule() {
	mappingRuleService := service.NewMappingRuleService(nil)
	getMappingRuleQuery := &query.GetMappingRuleQuery{}
	mappingRuleId, _ := controller.GetInt(":mappingRuleId")
	getMappingRuleQuery.MappingRuleId = mappingRuleId
	data, err := mappingRuleService.GetMappingRule(getMappingRuleQuery)
	controller.Response(data, err)
}

func (controller *MappingRuleController) RemoveMappingRule() {
	mappingRuleService := service.NewMappingRuleService(nil)
	removeMappingRuleCommand := &command.RemoveMappingRuleCommand{}
	controller.Unmarshal(removeMappingRuleCommand)
	mappingRuleId, _ := controller.GetInt(":mappingRuleId")
	removeMappingRuleCommand.MappingRuleId = mappingRuleId
	data, err := mappingRuleService.RemoveMappingRule(removeMappingRuleCommand)
	controller.Response(data, err)
}

func (controller *MappingRuleController) ListMappingRule() {
	mappingRuleService := service.NewMappingRuleService(nil)
	listMappingRuleQuery := &query.ListMappingRuleQuery{}
	offset, _ := controller.GetInt("offset")
	listMappingRuleQuery.Offset = offset
	limit, _ := controller.GetInt("limit")
	listMappingRuleQuery.Limit = limit
	data, err := mappingRuleService.ListMappingRule(listMappingRuleQuery)
	controller.Response(data, err)
}

func (controller *MappingRuleController) SearchMappingRule() {
	mappingRuleService := service.NewMappingRuleService(nil)
	cmd := &command.SearchCommand{}
	Must(controller.Unmarshal(cmd))
	cmd.Context = ParseContext(controller.BaseController)
	data, err := mappingRuleService.Search(cmd)
	controller.Response(data, err)
}

func (controller *MappingRuleController) PrepareMappingRule() {
	mappingRuleService := service.NewMappingRuleService(nil)
	prepareCommand := &command.PrepareCommand{}
	//controller.Unmarshal(prepareCommand)
	prepareCommand.TableId, _ = controller.GetInt("tableId")
	prepareCommand.FileId, _ = controller.GetInt("fileId")
	data, err := mappingRuleService.Prepare(prepareCommand)
	controller.Response(data, err)
}