dictionary_controller.go 2.6 KB
package backgroud_client

import (
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"

	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/dictionary/command"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/dictionary/query"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/dictionary/service"
)

type DictionaryController struct {
	baseController
}

func (controller *DictionaryController) CreateDictionary() {
	dictionaryService := service.NewDictionayService(nil)
	createCommand := &command.CreateDictionaryCommand{}
	err := controller.Unmarshal(createCommand)
	if err != nil {
		log.Logger.Debug("json err:" + err.Error())
	}
	createCommand.Operator = controller.GetOperator()
	data, err := dictionaryService.CreateDictionay(createCommand)
	controller.Response(data, err)
}

func (controller *DictionaryController) UpdateDictionary() {
	dictionaryService := service.NewDictionayService(nil)
	updateCommand := &command.UpdateDictionaryCommand{}
	err := controller.Unmarshal(updateCommand)
	if err != nil {
		log.Logger.Debug("json err:" + err.Error())
	}
	dictionaryId, _ := controller.GetInt64("::dictionaryId")
	updateCommand.Operator = controller.GetOperator()
	updateCommand.DictionaryId = dictionaryId
	data, err := dictionaryService.UpdateDictionay(updateCommand)
	controller.Response(data, err)
}

func (controller *DictionaryController) RemoveDictionary() {
	dictionaryService := service.NewDictionayService(nil)
	removeCommand := &command.RemoveDictionaryCommand{}
	err := controller.Unmarshal(removeCommand)
	if err != nil {
		log.Logger.Debug("json err:" + err.Error())
	}
	removeCommand.Operator = controller.GetOperator()
	data, err := dictionaryService.RemoveDictionay(removeCommand)
	controller.Response(data, err)
}

func (controller *DictionaryController) GetDictionary() {
	dictionaryService := service.NewDictionayService(nil)
	getQuery := &query.GetDictionaryQuery{}

	dictionaryId, _ := controller.GetInt64("::dictionaryId")
	getQuery.DictionaryId = int(dictionaryId)
	getQuery.Operator = controller.GetOperator()
	data, err := dictionaryService.GetDictionay(getQuery)
	controller.Response(data, err)
}

func (controller *DictionaryController) ListDictionary() {
	dictionaryService := service.NewDictionayService(nil)
	listQuery := &query.ListDictionaryQuery{}
	err := controller.Unmarshal(listQuery)
	if err != nil {
		log.Logger.Debug("json err:" + err.Error())
	}
	listQuery.Operator = controller.GetOperator()
	data, err := dictionaryService.ListDictionay(listQuery)
	controller.Response(data, err)
}