Files
ai-agent/internal/handlers/dashboard/customer_contact_handler.go
T
t 2bbf42b741 refactor(auth): delegate access control to be-system
Remove Agent Desk users, roles, login sessions, tokens, and local permission persistence. Expose the backend as an embeddable ai-agent module with host-provided subject lookup and operation authorization callbacks, and complete the frontend/backend repository split.
2026-08-21 00:41:07 +08:00

85 lines
2.4 KiB
Go

package dashboard
import (
"code.tczkiot.com/wlw/ai-agent/internal/builders"
"code.tczkiot.com/wlw/ai-agent/internal/pkg/constants"
"code.tczkiot.com/wlw/ai-agent/internal/pkg/dto/request"
"code.tczkiot.com/wlw/ai-agent/internal/pkg/httpx"
"code.tczkiot.com/wlw/ai-agent/internal/services"
"code.tczkiot.com/wlw/ai-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
)
// AnyList GET/POST /customer-contact/list?customerId=
func CustomerContactAnyList(ctx *gin.Context) {
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionCustomerView); err != nil {
httpx.WriteJSON(ctx, err)
return
}
customerID, _ := params.GetInt64(ctx, "customerId")
if customerID <= 0 {
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0065"))
return
}
list := services.CustomerContactService.FindActiveByCustomerID(customerID)
httpx.WriteJSON(ctx, builders.BuildCustomerContactList(list))
}
func CustomerContactPostCreate(ctx *gin.Context) {
user, err := services.AuthService.RequirePermission(ctx, constants.PermissionCustomerUpdate)
if err != nil {
httpx.WriteJSON(ctx, err)
return
}
req := request.CreateCustomerContactRequest{}
if err := params.ReadJSON(ctx, &req); err != nil {
httpx.WriteJSON(ctx, err)
return
}
item, err := services.CustomerContactService.CreateCustomerContact(req, user)
if err != nil {
httpx.WriteJSON(ctx, err)
return
}
ret := builders.BuildCustomerContactResponse(item)
httpx.WriteJSON(ctx, &ret)
}
func CustomerContactPostUpdate(ctx *gin.Context) {
user, err := services.AuthService.RequirePermission(ctx, constants.PermissionCustomerUpdate)
if err != nil {
httpx.WriteJSON(ctx, err)
return
}
req := request.UpdateCustomerContactRequest{}
if err := params.ReadJSON(ctx, &req); err != nil {
httpx.WriteJSON(ctx, err)
return
}
if err := services.CustomerContactService.UpdateCustomerContact(req, user); err != nil {
httpx.WriteJSON(ctx, err)
return
}
httpx.WriteJSON(ctx, nil)
}
func CustomerContactPostDelete(ctx *gin.Context) {
user, err := services.AuthService.RequirePermission(ctx, constants.PermissionCustomerUpdate)
if err != nil {
httpx.WriteJSON(ctx, err)
return
}
req := request.DeleteCustomerContactRequest{}
if err := params.ReadJSON(ctx, &req); err != nil {
httpx.WriteJSON(ctx, err)
return
}
if err := services.CustomerContactService.DeleteCustomerContact(req.ID, user); err != nil {
httpx.WriteJSON(ctx, err)
return
}
httpx.WriteJSON(ctx, nil)
}