role_controller.go 1.5 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 RoleController struct {
	beego.BaseController
}

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))
	}
}

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))
	}
}

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 {
		in.CompanyId = middlewares.GetCompanyId(controller.Ctx)
		controller.Response(ruService.Remove(in))
	}
}