Align GoChat with Chatwoot frontend contracts

This commit is contained in:
2026-06-13 22:13:32 +08:00
parent 71abf58636
commit d884fdda0a
162 changed files with 9825 additions and 528 deletions
+31 -15
View File
@@ -49,11 +49,15 @@ func (h *InboxHandler) WithAuditService(auditSvc *service.AuditService) *InboxHa
// List retrieves all inboxes for an account.
// GET /api/v1/accounts/:id/inboxes
func (h *InboxHandler) List(c *gin.Context) {
accountID, err := parseUintParam(c, "id")
if err != nil {
accountID := parseAccountIDParam(c)
if accountID == 0 {
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid account id"})
return
}
if !h.svc.Ready() {
response.AbortWithStatusError(c, http.StatusUnprocessableEntity, response.ErrInternal, "failed to list inboxes")
return
}
page := getPage(c)
perPage := getPageSize(c)
@@ -85,11 +89,15 @@ func (h *InboxHandler) List(c *gin.Context) {
// Get retrieves a single inbox.
// GET /api/v1/accounts/:id/inboxes/:inbox_id
func (h *InboxHandler) Get(c *gin.Context) {
accountID, err := parseUintParam(c, "id")
if err != nil {
accountID := parseAccountIDParam(c)
if accountID == 0 {
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid account id"})
return
}
if !h.svc.Ready() {
response.AbortWithStatusError(c, http.StatusUnprocessableEntity, response.ErrInternal, "failed to get inbox")
return
}
inboxID, err := parseUintParam(c, "inbox_id")
if err != nil {
@@ -122,8 +130,8 @@ func (h *InboxHandler) Get(c *gin.Context) {
// Create creates a new inbox.
// POST /api/v1/accounts/:id/inboxes
func (h *InboxHandler) Create(c *gin.Context) {
accountID, err := parseUintParam(c, "id")
if err != nil {
accountID := parseAccountIDParam(c)
if accountID == 0 {
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid account id"})
return
}
@@ -133,6 +141,10 @@ func (h *InboxHandler) Create(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"error": bindErr.Error()})
return
}
if !h.svc.Ready() {
response.AbortWithStatusError(c, http.StatusUnprocessableEntity, response.ErrInternal, "failed to create inbox")
return
}
inbox, svcErr := h.svc.Create(c.Request.Context(), accountID, req)
if svcErr != nil {
@@ -210,8 +222,8 @@ func (h *InboxHandler) WhatsAppAuthorization(c *gin.Context) {
// PUT /api/v1/accounts/:id/inboxes/:inbox_id
// Reference: Chatwoot inboxes#update
func (h *InboxHandler) Update(c *gin.Context) {
accountID, err := parseUintParam(c, "id")
if err != nil {
accountID := parseAccountIDParam(c)
if accountID == 0 {
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid account id"})
return
}
@@ -227,6 +239,10 @@ func (h *InboxHandler) Update(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"error": bindErr.Error()})
return
}
if !h.svc.Ready() {
response.AbortWithStatusError(c, http.StatusUnprocessableEntity, response.ErrInternal, "failed to update inbox")
return
}
inbox, svcErr := h.svc.Update(c.Request.Context(), accountID, inboxID, req)
if svcErr != nil {
@@ -262,11 +278,15 @@ func (h *InboxHandler) Update(c *gin.Context) {
// DELETE /api/v1/accounts/:id/inboxes/:inbox_id
// Reference: Chatwoot inboxes#destroy
func (h *InboxHandler) Delete(c *gin.Context) {
accountID, err := parseUintParam(c, "id")
if err != nil {
accountID := parseAccountIDParam(c)
if accountID == 0 {
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid account id"})
return
}
if !h.svc.Ready() {
response.AbortWithStatusError(c, http.StatusUnprocessableEntity, response.ErrInternal, "failed to delete inbox")
return
}
inboxID, err := parseUintParam(c, "inbox_id")
if err != nil {
@@ -919,11 +939,7 @@ func (h *InboxHandler) ListCampaigns(c *gin.Context) {
// POST /api/v1/accounts/:id/inboxes/:inbox_id/reset_secret
// Reference: Chatwoot inboxes_controller#reset_secret — only works for API inboxes
func (h *InboxHandler) ResetSecret(c *gin.Context) {
accountID, err := parseUintParam(c, "id")
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid account id"})
return
}
accountID := parseAccountIDParam(c)
inboxID, err := parseUintParam(c, "inbox_id")
if err != nil {