role_user_controller.go 1.6 KB
package controllers

import (
	"github.com/linmadan/egglib-go/core/application"
	"github.com/linmadan/egglib-go/web/beego"
	service "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role/command"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
)

type RoleUserController struct {
	beego.BaseController
}

func (controller *RoleUserController) CreateRoleUser() {
	ruService := service.NewRoleUserService()
	in := &command.UserRoleCreateCommand{}
	if err := controller.Unmarshal(in); err != nil {
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
	} else {
		in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
		controller.Response(ruService.Create(in))
	}
}

func (controller *RoleUserController) RemoveRoleUser() {
	ruService := service.NewRoleUserService()
	in := &command.UserRoleDeleteCommand{}
	if err := controller.Unmarshal(in); err != nil {
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
	} else {
		in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
		controller.Response(ruService.Remove(in))
	}
}

func (controller *RoleUserController) ListRoleUser() {
	ruService := service.NewRoleUserService()
	in := &command.UserRoleQueryCommand{}
	if err := controller.Unmarshal(in); err != nil {
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
	} else {
		in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
		controller.Response(ruService.ListRole(in))
	}
}