orgs_controller.go 3.2 KB
package web_client

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

type OrgsController struct {
	baseController
}

func (controller *OrgsController) OrgAdd() {
	orgsService := service.NewOrgsService(nil)
	orgAddCommand := &command.OrgAddCommand{}
	err := controller.Unmarshal(orgAddCommand)
	if err != nil {
		log.Logger.Debug("json err:" + err.Error())
	}
	orgAddCommand.Operator = controller.GetOperator()
	data, err := orgsService.OrgAdd(orgAddCommand)
	controller.Response(data, err)
}

func (controller *OrgsController) OrgUpdate() {
	orgsService := service.NewOrgsService(nil)
	orgUpdateCommand := &command.OrgUpdateCommand{}
	err := controller.Unmarshal(orgUpdateCommand)
	if err != nil {
		log.Logger.Debug("json err:" + err.Error())
	}
	orgId := controller.GetString(":orgId")
	orgUpdateCommand.OrgId = orgId
	orgUpdateCommand.Operator = controller.GetOperator()
	data, err := orgsService.OrgUpdate(orgUpdateCommand)
	controller.Response(data, err)
}

func (controller *OrgsController) OrgList() {
	orgsService := service.NewOrgsService(nil)
	orgListQuery := &query.OrgListQuery{}
	err := controller.Unmarshal(orgListQuery)
	if err != nil {
		log.Logger.Debug("json err:" + err.Error())
	}
	orgListQuery.Operator = controller.GetOperator()
	data, err := orgsService.OrgList(orgListQuery)
	controller.Response(data, err)
}

func (controller *OrgsController) OrgGet() {
	orgsService := service.NewOrgsService(nil)
	orgGetQuery := &query.OrgGetQuery{}
	orgId := controller.GetString(":orgId")
	orgGetQuery.OrgId = orgId
	orgGetQuery.Operator = controller.GetOperator()
	data, err := orgsService.OrgGet(orgGetQuery)
	controller.Response(data, err)
}

func (controller *OrgsController) OrgEnable() {
	orgsService := service.NewOrgsService(nil)
	orgEnableCommand := &command.OrgEnableCommand{}
	err := controller.Unmarshal(orgEnableCommand)
	if err != nil {
		log.Logger.Debug("json err:" + err.Error())
	}
	orgEnableCommand.Operator = controller.GetOperator()
	data, err := orgsService.OrgEnable(orgEnableCommand)
	controller.Response(data, err)
}

func (controller *OrgsController) OrgGetSubDepartment() {
	orgsService := service.NewOrgsService(nil)
	orgGetSubDepartmentQuery := &query.OrgGetSubDepartmentQuery{}
	err := controller.Unmarshal(orgGetSubDepartmentQuery)
	if err != nil {
		log.Logger.Debug("json err:" + err.Error())
	}
	orgGetSubDepartmentQuery.Operator = controller.GetOperator()
	data, err := orgsService.OrgGetSubDepartment(orgGetSubDepartmentQuery)
	controller.Response(data, err)
}

func (controller *OrgsController) DepartmentUsers() {
	orgService := service.OrgsService{}
	departmentsUsersQuery := &query.DepartmentsUsersQuery{}
	err := controller.Unmarshal(departmentsUsersQuery)
	if err != nil {
		controller.Response(nil, err)
		return
	}
	departmentsUsersQuery.Operator = controller.GetOperator()
	data, err := orgService.DepartmentsUsers(departmentsUsersQuery)
	controller.Response(data, err)
}