Files
ai-agent/internal/controllers/dashboard/ticket_resolution_code_controller.go
T
mlogclub 62416baabc Refactor API endpoints to use /api/dashboard instead of /api/console
- Updated all relevant API functions in agent.ts, company.ts, customer-contact.ts, customer.ts, dashboard.ts, ticket-config.ts, and ticket.ts to point to the new /api/dashboard paths.
- Ensured that all request methods and payload structures remain unchanged to maintain existing functionality.
2026-04-15 17:12:30 +08:00

86 lines
3.1 KiB
Go

package dashboard
import (
"cs-agent/internal/builders"
"cs-agent/internal/pkg/constants"
"cs-agent/internal/pkg/dto/request"
"cs-agent/internal/pkg/enums"
"cs-agent/internal/services"
"github.com/kataras/iris/v12"
"github.com/mlogclub/simple/sqls"
"github.com/mlogclub/simple/web"
"github.com/mlogclub/simple/web/params"
)
type TicketResolutionCodeController struct{ Ctx iris.Context }
func (c *TicketResolutionCodeController) AnyList() *web.JsonResult {
if _, err := services.AuthService.RequirePermission(c.Ctx, constants.PermissionTicketResolutionCodeView); err != nil {
return web.JsonError(err)
}
cnd := params.NewPagedSqlCnd(c.Ctx,
params.QueryFilter{ParamName: "status"},
params.QueryFilter{ParamName: "name", Op: params.Like},
).Asc("sort_no").Desc("id")
if _, ok := params.Get(c.Ctx, "status"); !ok {
cnd.Where("status <> ?", enums.StatusDeleted)
}
list, paging := services.TicketResolutionCodeService.FindPageByCnd(cnd)
return web.JsonData(&web.PageResult{Results: builders.BuildTicketResolutionCodeList(list), Page: paging})
}
func (c *TicketResolutionCodeController) GetList_all() *web.JsonResult {
if _, err := services.AuthService.RequirePermission(c.Ctx, constants.PermissionTicketResolutionCodeView); err != nil {
return web.JsonError(err)
}
list := services.TicketResolutionCodeService.Find(sqls.NewCnd().Eq("status", enums.StatusOk).Asc("sort_no").Desc("id"))
return web.JsonData(builders.BuildTicketResolutionCodeList(list))
}
func (c *TicketResolutionCodeController) PostCreate() *web.JsonResult {
operator, err := services.AuthService.RequirePermission(c.Ctx, constants.PermissionTicketResolutionCodeCreate)
if err != nil {
return web.JsonError(err)
}
req := request.CreateTicketResolutionCodeRequest{}
if err := params.ReadJSON(c.Ctx, &req); err != nil {
return web.JsonError(err)
}
item, err := services.TicketResolutionCodeService.CreateTicketResolutionCode(req, operator)
if err != nil {
return web.JsonError(err)
}
return web.JsonData(builders.BuildTicketResolutionCode(item))
}
func (c *TicketResolutionCodeController) PostUpdate() *web.JsonResult {
operator, err := services.AuthService.RequirePermission(c.Ctx, constants.PermissionTicketResolutionCodeUpdate)
if err != nil {
return web.JsonError(err)
}
req := request.UpdateTicketResolutionCodeRequest{}
if err := params.ReadJSON(c.Ctx, &req); err != nil {
return web.JsonError(err)
}
if err := services.TicketResolutionCodeService.UpdateTicketResolutionCode(req, operator); err != nil {
return web.JsonError(err)
}
return web.JsonSuccess()
}
func (c *TicketResolutionCodeController) PostDelete() *web.JsonResult {
operator, err := services.AuthService.RequirePermission(c.Ctx, constants.PermissionTicketResolutionCodeDelete)
if err != nil {
return web.JsonError(err)
}
req := request.DeleteTicketResolutionCodeRequest{}
if err := params.ReadJSON(c.Ctx, &req); err != nil {
return web.JsonError(err)
}
if err := services.TicketResolutionCodeService.DeleteTicketResolutionCode(req.ID, operator); err != nil {
return web.JsonError(err)
}
return web.JsonSuccess()
}