fix(routes): align whatsapp call ids

This commit is contained in:
2026-06-07 13:04:27 +08:00
parent 5062acec61
commit 7ea4bf9362
7 changed files with 53 additions and 51 deletions
@@ -186,8 +186,8 @@ func (h *AgentCapacityHandler) CreateInboxLimit(c *gin.Context) {
response.AbortWithStatusError(c, http.StatusUnauthorized, response.ErrUnauthorized, "account not identified")
return
}
policyID, err := parseUintParam(c, "id")
if err != nil {
policyID, err := parseUintAnyParam(c, "agent_capacity_policy_id", "id")
if err != nil || policyID == 0 {
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid id")
return
}
@@ -217,13 +217,13 @@ func (h *AgentCapacityHandler) UpdateInboxLimit(c *gin.Context) {
response.AbortWithStatusError(c, http.StatusUnauthorized, response.ErrUnauthorized, "account not identified")
return
}
policyID, err := parseUintParam(c, "id")
if err != nil {
policyID, err := parseUintAnyParam(c, "agent_capacity_policy_id", "id")
if err != nil || policyID == 0 {
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid id")
return
}
limitID, err := parseUintParam(c, "limit_id")
if err != nil {
limitID, err := parseUintAnyParam(c, "limit_id", "id")
if err != nil || limitID == 0 {
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid limit id")
return
}
@@ -253,13 +253,13 @@ func (h *AgentCapacityHandler) DeleteInboxLimit(c *gin.Context) {
response.AbortWithStatusError(c, http.StatusUnauthorized, response.ErrUnauthorized, "account not identified")
return
}
policyID, err := parseUintParam(c, "id")
if err != nil {
policyID, err := parseUintAnyParam(c, "agent_capacity_policy_id", "id")
if err != nil || policyID == 0 {
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid id")
return
}
limitID, err := parseUintParam(c, "limit_id")
if err != nil {
limitID, err := parseUintAnyParam(c, "limit_id", "id")
if err != nil || limitID == 0 {
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid limit id")
return
}
@@ -283,8 +283,8 @@ func (h *AgentCapacityHandler) ListUsers(c *gin.Context) {
response.AbortWithStatusError(c, http.StatusUnauthorized, response.ErrUnauthorized, "account not identified")
return
}
policyID, err := parseUintParam(c, "id")
if err != nil {
policyID, err := parseUintAnyParam(c, "agent_capacity_policy_id", "id")
if err != nil || policyID == 0 {
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid id")
return
}
@@ -306,8 +306,8 @@ func (h *AgentCapacityHandler) CreateUser(c *gin.Context) {
response.AbortWithStatusError(c, http.StatusUnauthorized, response.ErrUnauthorized, "account not identified")
return
}
policyID, err := parseUintParam(c, "id")
if err != nil {
policyID, err := parseUintAnyParam(c, "agent_capacity_policy_id", "id")
if err != nil || policyID == 0 {
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid id")
return
}
@@ -340,13 +340,13 @@ func (h *AgentCapacityHandler) DeleteUser(c *gin.Context) {
response.AbortWithStatusError(c, http.StatusUnauthorized, response.ErrUnauthorized, "account not identified")
return
}
policyID, err := parseUintParam(c, "id")
if err != nil {
policyID, err := parseUintAnyParam(c, "agent_capacity_policy_id", "id")
if err != nil || policyID == 0 {
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid id")
return
}
userID, err := parseUintParam(c, "user_id")
if err != nil {
userID, err := parseUintAnyParam(c, "user_id", "id")
if err != nil || userID == 0 {
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid user id")
return
}
@@ -25,7 +25,7 @@ func NewWhatsAppCallHandler(svc *service.WhatsAppCallService) *WhatsAppCallHandl
}
// Show returns a Chatwoot WhatsApp call payload.
// GET /api/v1/accounts/:account_id/whatsapp_calls/:call_id
// GET /api/v1/accounts/:account_id/whatsapp_calls/:id
func (h *WhatsAppCallHandler) Show(c *gin.Context) {
accountID, callID, ok := h.parseAccountCallParams(c)
if !ok {
@@ -72,7 +72,7 @@ func (h *WhatsAppCallHandler) Initiate(c *gin.Context) {
}
// Accept forwards an SDP answer to Meta and returns the updated call payload.
// POST /api/v1/accounts/:account_id/whatsapp_calls/:call_id/accept
// POST /api/v1/accounts/:account_id/whatsapp_calls/:id/accept
func (h *WhatsAppCallHandler) Accept(c *gin.Context) {
accountID, callID, ok := h.parseAccountCallParams(c)
if !ok {
@@ -91,7 +91,7 @@ func (h *WhatsAppCallHandler) Accept(c *gin.Context) {
}
// Reject rejects a ringing WhatsApp call.
// POST /api/v1/accounts/:account_id/whatsapp_calls/:call_id/reject
// POST /api/v1/accounts/:account_id/whatsapp_calls/:id/reject
func (h *WhatsAppCallHandler) Reject(c *gin.Context) {
accountID, callID, ok := h.parseAccountCallParams(c)
if !ok {
@@ -106,7 +106,7 @@ func (h *WhatsAppCallHandler) Reject(c *gin.Context) {
}
// Terminate terminates an active or ringing WhatsApp call.
// POST /api/v1/accounts/:account_id/whatsapp_calls/:call_id/terminate
// POST /api/v1/accounts/:account_id/whatsapp_calls/:id/terminate
func (h *WhatsAppCallHandler) Terminate(c *gin.Context) {
accountID, callID, ok := h.parseAccountCallParams(c)
if !ok {
@@ -121,7 +121,7 @@ func (h *WhatsAppCallHandler) Terminate(c *gin.Context) {
}
// UploadRecording attaches an audio recording to the linked voice_call message.
// POST /api/v1/accounts/:account_id/whatsapp_calls/:call_id/upload_recording
// POST /api/v1/accounts/:account_id/whatsapp_calls/:id/upload_recording
func (h *WhatsAppCallHandler) UploadRecording(c *gin.Context) {
accountID, callID, ok := h.parseAccountCallParams(c)
if !ok {
@@ -146,8 +146,8 @@ func (h *WhatsAppCallHandler) parseAccountCallParams(c *gin.Context) (uint, uint
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid account id")
return 0, 0, false
}
callID, err := parseUintParam(c, "call_id")
if err != nil {
callID, err := parseUintAnyParam(c, "call_id", "id")
if err != nil || callID == 0 {
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid call id")
return 0, 0, false
}
@@ -70,12 +70,12 @@ func setupWhatsAppCallHandlerTest(t *testing.T) (*gin.Engine, *gorm.DB, *model.A
c.Set("user_id", uint(7))
c.Next()
})
router.GET("/api/v1/accounts/:account_id/whatsapp_calls/:call_id", handler.Show)
router.GET("/api/v1/accounts/:account_id/whatsapp_calls/:id", handler.Show)
router.POST("/api/v1/accounts/:account_id/whatsapp_calls/initiate", handler.Initiate)
router.POST("/api/v1/accounts/:account_id/whatsapp_calls/:call_id/accept", handler.Accept)
router.POST("/api/v1/accounts/:account_id/whatsapp_calls/:call_id/reject", handler.Reject)
router.POST("/api/v1/accounts/:account_id/whatsapp_calls/:call_id/terminate", handler.Terminate)
router.POST("/api/v1/accounts/:account_id/whatsapp_calls/:call_id/upload_recording", handler.UploadRecording)
router.POST("/api/v1/accounts/:account_id/whatsapp_calls/:id/accept", handler.Accept)
router.POST("/api/v1/accounts/:account_id/whatsapp_calls/:id/reject", handler.Reject)
router.POST("/api/v1/accounts/:account_id/whatsapp_calls/:id/terminate", handler.Terminate)
router.POST("/api/v1/accounts/:account_id/whatsapp_calls/:id/upload_recording", handler.UploadRecording)
return router, db, account, conversation
}