审查视图

pkg/port/beego/controllers/role_controller.go 2.0 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14
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 RoleController struct {
	beego.BaseController
}
郑周 authored
15 16 17 18 19 20 21 22 23
//	func (controller *RoleController) CreateRole() {
//		ruService := service.NewRoleService()
//		in := &command.CreateRoleCommand{}
//		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))
//		}
郑周 authored
24 25
//	}
//
郑周 authored
26 27 28 29 30 31 32 33 34
//	func (controller *RoleController) UpdateRole() {
//		ruService := service.NewRoleService()
//		in := &command.UpdateRoleCommand{}
//		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.Update(in))
//		}
郑周 authored
35
//	}
郑周 authored
36 37 38 39 40 41 42 43 44 45 46
func (controller *RoleController) RemoveRole() {
	ruService := service.NewRoleService()
	in := &command.DeleteRoleCommand{}
	if err := controller.Unmarshal(in); err != nil {
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
	} else {
		ua := middlewares.GetUser(controller.Ctx)
		in.CompanyId = ua.CompanyId
		controller.Response(ruService.Remove(in))
	}
}
郑周 authored
47 48 49 50 51 52 53

func (controller *RoleController) ListForUserRole() {
	ruService := service.NewRoleService()
	in := &command.QueryRoleUserCommand{}
	if err := controller.Unmarshal(in); err != nil {
		controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
	} else {
郑周 authored
54 55
		ua := middlewares.GetUser(controller.Ctx)
		in.CompanyId = ua.CompanyId
郑周 authored
56 57 58
		controller.Response(ruService.ListForUser(in))
	}
}