审查视图

pkg/port/beego/controllers/role_user_controller.go 1.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
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 {
郑周 authored
21 22 23
		ua := middlewares.GetUser(controller.Ctx)
		in.CompanyId = ua.CompanyId
		//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
24 25 26 27 28 29 30 31 32 33
		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 {
郑周 authored
34 35 36
		ua := middlewares.GetUser(controller.Ctx)
		in.CompanyId = ua.CompanyId
		//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
37 38 39
		controller.Response(ruService.Remove(in))
	}
}
郑周 authored
40 41 42 43 44 45 46

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 {
郑周 authored
47 48 49
		ua := middlewares.GetUser(controller.Ctx)
		in.CompanyId = ua.CompanyId
		//in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
郑周 authored
50 51 52
		controller.Response(ruService.ListRole(in))
	}
}