Files
ai-agent/internal/controllers/dashboard/permission_controller.go
T
mlogclub 79614b2d07 Refactor import paths to use internal/pkg/httpx/params
- Updated multiple repository and service files to replace imports from "github.com/mlogclub/simple/web/params" with "cs-agent/internal/pkg/httpx/params".
- Adjusted context handling in auth_service and ws_service to use gin.Context instead of iris.Context.
- Ensured consistent usage of HTTP status responses across websocket handlers.
2026-05-23 22:10:20 +08:00

72 lines
2.0 KiB
Go

package dashboard
import (
"cs-agent/internal/pkg/constants"
"cs-agent/internal/pkg/dto/response"
"cs-agent/internal/services"
"cs-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
"github.com/mlogclub/simple/common/strs"
"github.com/mlogclub/simple/web"
)
type PermissionController struct {
Ctx *gin.Context
}
func (c *PermissionController) AnyList() *web.JsonResult {
if _, err := services.AuthService.RequirePermission(c.Ctx, constants.PermissionPermissionView); err != nil {
return web.JsonError(err)
}
cnd := params.NewPagedSqlCnd(c.Ctx,
params.QueryFilter{ParamName: "groupName"},
params.QueryFilter{ParamName: "type"},
params.QueryFilter{ParamName: "status"},
).Desc("id")
if keyword, _ := params.Get(c.Ctx, "keyword"); strs.IsNotBlank(keyword) {
cnd.Where("(name LIKE ? OR code LIKE ?)", "%"+keyword+"%", "%"+keyword+"%")
}
list, paging := services.PermissionService.FindPageByCnd(cnd)
results := make([]response.PermissionResponse, 0, len(list))
for _, item := range list {
results = append(results, response.PermissionResponse{
ID: item.ID,
Name: item.Name,
Code: item.Code,
Type: item.Type,
GroupName: item.GroupName,
Method: item.Method,
ApiPath: item.APIPath,
Status: item.Status,
SortNo: item.SortNo,
})
}
return web.JsonData(&web.PageResult{Results: results, Page: paging})
}
func (c *PermissionController) GetBy(id int64) *web.JsonResult {
if _, err := services.AuthService.RequirePermission(c.Ctx, constants.PermissionPermissionView); err != nil {
return web.JsonError(err)
}
item := services.PermissionService.Get(id)
if item == nil {
return web.JsonErrorMsg("权限不存在")
}
return web.JsonData(&response.PermissionResponse{
ID: item.ID,
Name: item.Name,
Code: item.Code,
Type: item.Type,
GroupName: item.GroupName,
Method: item.Method,
ApiPath: item.APIPath,
Status: item.Status,
SortNo: item.SortNo,
})
}