permission_controller.go 1.3 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/permission"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/permission/command"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares"
)

type PermissionController struct {
	beego.BaseController
}

func (controller *PermissionController) UpdatePermission() {
	ruService := service.NewPermissionService()
	in := &command.UpdatePermissionCommand{}
	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
		in.UserId = ua.UserId
		controller.Response(ruService.Update(in))
	}
}

func (controller *PermissionController) GetPermission() {
	ruService := service.NewPermissionService()
	in := &command.GetPermissionCommand{}
	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.Get(in))
	}
}