feat(conversations): align index finder filters
This commit is contained in:
@@ -61,30 +61,26 @@ func (h *ConversationHandler) List(c *gin.Context) {
|
||||
|
||||
p := pagination.Parse(c)
|
||||
|
||||
// Support status filter via query param
|
||||
status := c.Query("status")
|
||||
var conversations []model.Conversation
|
||||
var total int64
|
||||
|
||||
if status != "" {
|
||||
result, count, svcErr := h.conversationSvc.ListByStatus(c.Request.Context(), accountID, status, p.Offset, p.PerPage)
|
||||
if svcErr != nil {
|
||||
handleServiceError(c, svcErr)
|
||||
return
|
||||
}
|
||||
conversations = result
|
||||
total = count
|
||||
} else {
|
||||
result, count, svcErr := h.conversationSvc.ListByAccount(c.Request.Context(), accountID, p.Offset, p.PerPage)
|
||||
if svcErr != nil {
|
||||
handleServiceError(c, svcErr)
|
||||
return
|
||||
}
|
||||
conversations = result
|
||||
total = count
|
||||
var params service.FilterParams
|
||||
if err := c.ShouldBindQuery(¶ms); err != nil {
|
||||
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrValidation, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, serializeConversationList(c.Request.Context(), h.conversationSvc.DB(), conversations, total))
|
||||
result, svcErr := h.conversationSvc.ListWithFinder(c.Request.Context(), accountID, getUserID(c), params, p.Offset, p.PerPage)
|
||||
if svcErr != nil {
|
||||
handleServiceError(c, svcErr)
|
||||
return
|
||||
}
|
||||
|
||||
payload := serializeConversationList(c.Request.Context(), h.conversationSvc.DB(), result.Conversations, result.Count.AllCount)
|
||||
payload.Data.Meta = chatwootConversationCounts{
|
||||
MineCount: result.Count.MineCount,
|
||||
AssignedCount: result.Count.AssignedCount,
|
||||
UnassignedCount: result.Count.UnassignedCount,
|
||||
AllCount: result.Count.AllCount,
|
||||
}
|
||||
c.JSON(http.StatusOK, payload)
|
||||
}
|
||||
|
||||
// Create creates a new conversation.
|
||||
|
||||
Reference in New Issue
Block a user