Refactor controllers to use httpx for JSON responses and eliminate context dependency

- Updated TagController methods to use httpx.WriteJSON for consistent JSON response handling.
- Refactored TicketController to replace context-dependent methods with standalone functions using httpx.
- Modified UserController to utilize httpx for error handling and response formatting.
- Adjusted WechatController to remove context dependency and standardize response handling.
This commit is contained in:
mlogclub
2026-05-23 22:22:18 +08:00
parent 7fdf96dd9d
commit e9d2e41f9e
34 changed files with 2395 additions and 2313 deletions
@@ -3,30 +3,29 @@ package dashboard
import (
"cs-agent/internal/pkg/constants"
"cs-agent/internal/pkg/dto/response"
"cs-agent/internal/pkg/httpx"
"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)
func PermissionAnyList(ctx *gin.Context) {
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionPermissionView); err != nil {
httpx.WriteJSON(ctx, err)
return
}
cnd := params.NewPagedSqlCnd(c.Ctx,
cnd := params.NewPagedSqlCnd(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) {
if keyword, _ := params.Get(ctx, "keyword"); strs.IsNotBlank(keyword) {
cnd.Where("(name LIKE ? OR code LIKE ?)", "%"+keyword+"%", "%"+keyword+"%")
}
@@ -45,19 +44,22 @@ func (c *PermissionController) AnyList() *web.JsonResult {
SortNo: item.SortNo,
})
}
return web.JsonData(&web.PageResult{Results: results, Page: paging})
httpx.WriteJSON(ctx, &web.PageResult{Results: results, Page: paging})
return
}
func (c *PermissionController) GetBy(id int64) *web.JsonResult {
if _, err := services.AuthService.RequirePermission(c.Ctx, constants.PermissionPermissionView); err != nil {
return web.JsonError(err)
func PermissionGetBy(ctx *gin.Context, id int64) {
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionPermissionView); err != nil {
httpx.WriteJSON(ctx, err)
return
}
item := services.PermissionService.Get(id)
if item == nil {
return web.JsonErrorMsg("权限不存在")
httpx.WriteJSON(ctx, web.JsonErrorMsg("权限不存在"))
return
}
return web.JsonData(&response.PermissionResponse{
httpx.WriteJSON(ctx, &response.PermissionResponse{
ID: item.ID,
Name: item.Name,
Code: item.Code,
@@ -68,4 +70,5 @@ func (c *PermissionController) GetBy(id int64) *web.JsonResult {
Status: item.Status,
SortNo: item.SortNo,
})
return
}