feat(routes): expand account parity coverage
This commit is contained in:
@@ -151,4 +151,72 @@ func (h *InboxMemberHandler) UpdateMultiple(c *gin.Context) {
|
||||
"members": members,
|
||||
"meta": gin.H{"count": len(members)},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// ShowAccountScoped retrieves all agents assigned to an inbox using Chatwoot's account-level route.
|
||||
// GET /api/v1/accounts/:account_id/inbox_members/:inbox_id
|
||||
func (h *InboxMemberHandler) ShowAccountScoped(c *gin.Context) {
|
||||
inboxID, err := parseUintParam(c, "inbox_id")
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid inbox id"})
|
||||
return
|
||||
}
|
||||
|
||||
members, svcErr := h.svc.ListByInbox(c.Request.Context(), inboxID)
|
||||
if svcErr != nil {
|
||||
c.JSON(http.StatusUnprocessableEntity, gin.H{"error": "failed to list inbox members"})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"members": members, "meta": gin.H{"count": len(members)}})
|
||||
}
|
||||
|
||||
// CreateAccountScoped adds or replaces inbox members using Chatwoot's account-level create route.
|
||||
// POST /api/v1/accounts/:account_id/inbox_members
|
||||
func (h *InboxMemberHandler) CreateAccountScoped(c *gin.Context) {
|
||||
h.updateAccountScoped(c)
|
||||
}
|
||||
|
||||
// UpdateAccountScoped replaces all members of an inbox using Chatwoot's account-level update route.
|
||||
// PATCH /api/v1/accounts/:account_id/inbox_members
|
||||
func (h *InboxMemberHandler) UpdateAccountScoped(c *gin.Context) {
|
||||
h.updateAccountScoped(c)
|
||||
}
|
||||
|
||||
func (h *InboxMemberHandler) updateAccountScoped(c *gin.Context) {
|
||||
var req service.UpdateMultipleRequest
|
||||
if bindErr := c.ShouldBindJSON(&req); bindErr != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": bindErr.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
members, svcErr := h.svc.UpdateMultiple(c.Request.Context(), req)
|
||||
if svcErr != nil {
|
||||
c.JSON(http.StatusUnprocessableEntity, gin.H{"error": "failed to update members"})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"members": members, "meta": gin.H{"count": len(members)}})
|
||||
}
|
||||
|
||||
// DestroyAccountScoped removes selected users from an inbox using Chatwoot's account-level route.
|
||||
// DELETE /api/v1/accounts/:account_id/inbox_members
|
||||
func (h *InboxMemberHandler) DestroyAccountScoped(c *gin.Context) {
|
||||
var req struct {
|
||||
InboxID uint `json:"inbox_id" binding:"required"`
|
||||
UserIDs []uint `json:"user_ids" binding:"required"`
|
||||
}
|
||||
if bindErr := c.ShouldBindJSON(&req); bindErr != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": bindErr.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
for _, userID := range req.UserIDs {
|
||||
if svcErr := h.svc.RemoveMember(c.Request.Context(), req.InboxID, userID); svcErr != nil {
|
||||
c.JSON(http.StatusUnprocessableEntity, gin.H{"error": "failed to remove member"})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
c.Status(http.StatusOK)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user