Files
ai-agent/internal/controllers/dashboard/customer_contact_controller.go
T

90 lines
2.4 KiB
Go
Raw Normal View History

package dashboard
2026-04-09 10:01:23 +08:00
import (
"cs-agent/internal/builders"
"cs-agent/internal/pkg/constants"
"cs-agent/internal/pkg/dto/request"
"cs-agent/internal/pkg/httpx"
2026-04-09 10:01:23 +08:00
"cs-agent/internal/services"
"cs-agent/internal/pkg/httpx/params"
"github.com/gin-gonic/gin"
2026-04-09 10:01:23 +08:00
"github.com/mlogclub/simple/web"
)
// 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
2026-04-09 10:01:23 +08:00
}
customerID, _ := params.GetInt64(ctx, "customerId")
2026-04-09 10:01:23 +08:00
if customerID <= 0 {
httpx.WriteJSON(ctx, web.JsonErrorMsg("customerId 必填"))
return
2026-04-09 10:01:23 +08:00
}
list := services.CustomerContactService.FindActiveByCustomerID(customerID)
httpx.WriteJSON(ctx, builders.BuildCustomerContactList(list))
return
2026-04-09 10:01:23 +08:00
}
func CustomerContactPostCreate(ctx *gin.Context) {
user, err := services.AuthService.RequirePermission(ctx, constants.PermissionCustomerUpdate)
2026-04-09 10:01:23 +08:00
if err != nil {
httpx.WriteJSON(ctx, err)
return
2026-04-09 10:01:23 +08:00
}
req := request.CreateCustomerContactRequest{}
if err := params.ReadJSON(ctx, &req); err != nil {
httpx.WriteJSON(ctx, err)
return
2026-04-09 10:01:23 +08:00
}
item, err := services.CustomerContactService.CreateCustomerContact(req, user)
if err != nil {
httpx.WriteJSON(ctx, err)
return
2026-04-09 10:01:23 +08:00
}
ret := builders.BuildCustomerContactResponse(item)
httpx.WriteJSON(ctx, &ret)
return
2026-04-09 10:01:23 +08:00
}
func CustomerContactPostUpdate(ctx *gin.Context) {
user, err := services.AuthService.RequirePermission(ctx, constants.PermissionCustomerUpdate)
2026-04-09 10:01:23 +08:00
if err != nil {
httpx.WriteJSON(ctx, err)
return
2026-04-09 10:01:23 +08:00
}
req := request.UpdateCustomerContactRequest{}
if err := params.ReadJSON(ctx, &req); err != nil {
httpx.WriteJSON(ctx, err)
return
2026-04-09 10:01:23 +08:00
}
if err := services.CustomerContactService.UpdateCustomerContact(req, user); err != nil {
httpx.WriteJSON(ctx, err)
return
2026-04-09 10:01:23 +08:00
}
httpx.WriteJSON(ctx, nil)
return
2026-04-09 10:01:23 +08:00
}
func CustomerContactPostDelete(ctx *gin.Context) {
user, err := services.AuthService.RequirePermission(ctx, constants.PermissionCustomerUpdate)
2026-04-09 10:01:23 +08:00
if err != nil {
httpx.WriteJSON(ctx, err)
return
2026-04-09 10:01:23 +08:00
}
req := request.DeleteCustomerContactRequest{}
if err := params.ReadJSON(ctx, &req); err != nil {
httpx.WriteJSON(ctx, err)
return
2026-04-09 10:01:23 +08:00
}
if err := services.CustomerContactService.DeleteCustomerContact(req.ID, user); err != nil {
httpx.WriteJSON(ctx, err)
return
2026-04-09 10:01:23 +08:00
}
httpx.WriteJSON(ctx, nil)
return
2026-04-09 10:01:23 +08:00
}