1:1
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
@@ -23,6 +24,7 @@ type ConversationHandler struct {
|
||||
conversationSvc *service.ConversationService
|
||||
messageSvc *service.MessageService
|
||||
auditSvc *service.AuditService
|
||||
presence contactPresenceReader
|
||||
}
|
||||
|
||||
const chatwootAttachmentResultsPerPage = 100
|
||||
@@ -37,6 +39,15 @@ func (h *ConversationHandler) WithAuditService(auditSvc *service.AuditService) *
|
||||
return h
|
||||
}
|
||||
|
||||
func (h *ConversationHandler) WithContactPresence(presence contactPresenceReader) *ConversationHandler {
|
||||
h.presence = presence
|
||||
return h
|
||||
}
|
||||
|
||||
func (h *ConversationHandler) requestContext(c *gin.Context) context.Context {
|
||||
return withContactPresence(c.Request.Context(), h.presence)
|
||||
}
|
||||
|
||||
// @Summary List conversations for an account
|
||||
// @Description Retrieves all conversations for an account with pagination, optionally filtered by status query param
|
||||
// @Tags Conversations
|
||||
@@ -73,7 +84,7 @@ func (h *ConversationHandler) List(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
payload := serializeConversationList(c.Request.Context(), h.conversationSvc.DB(), result.Conversations, result.Count.AllCount)
|
||||
payload := serializeConversationList(h.requestContext(c), h.conversationSvc.DB(), result.Conversations, result.Count.AllCount)
|
||||
payload.Data.Meta = chatwootConversationCounts{
|
||||
MineCount: result.Count.MineCount,
|
||||
AssignedCount: result.Count.AssignedCount,
|
||||
@@ -111,7 +122,7 @@ func (h *ConversationHandler) Create(c *gin.Context) {
|
||||
Action: "update",
|
||||
AuditedChanges: gin.H{"status": conversation.Status, "priority": conversation.Priority, "sla_policy_id": conversation.SlaPolicyID},
|
||||
})
|
||||
c.JSON(http.StatusOK, serializeConversation(c.Request.Context(), h.conversationSvc.DB(), conversation))
|
||||
c.JSON(http.StatusOK, serializeConversation(h.requestContext(c), h.conversationSvc.DB(), conversation))
|
||||
}
|
||||
|
||||
// @Summary Get a single conversation
|
||||
@@ -145,7 +156,7 @@ func (h *ConversationHandler) Get(c *gin.Context) {
|
||||
handleServiceError(c, svcErr)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, serializeConversation(c.Request.Context(), h.conversationSvc.DB(), conversation))
|
||||
c.JSON(http.StatusOK, serializeConversation(h.requestContext(c), h.conversationSvc.DB(), conversation))
|
||||
}
|
||||
|
||||
// Update updates a conversation (status, priority).
|
||||
@@ -179,7 +190,7 @@ func (h *ConversationHandler) Update(c *gin.Context) {
|
||||
handleServiceError(c, svcErr)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, serializeConversation(c.Request.Context(), h.conversationSvc.DB(), conversation))
|
||||
c.JSON(http.StatusOK, serializeConversation(h.requestContext(c), h.conversationSvc.DB(), conversation))
|
||||
}
|
||||
|
||||
// Delete soft-deletes a conversation.
|
||||
@@ -439,7 +450,7 @@ func (h *ConversationHandler) UpdateLabels(c *gin.Context) {
|
||||
handleServiceError(c, svcErr)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, serializeConversation(c.Request.Context(), h.conversationSvc.DB(), conversation))
|
||||
c.JSON(http.StatusOK, serializeConversation(h.requestContext(c), h.conversationSvc.DB(), conversation))
|
||||
}
|
||||
|
||||
// @Summary Search conversations
|
||||
@@ -481,7 +492,7 @@ func (h *ConversationHandler) Search(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, serializeConversationSearchList(c.Request.Context(), h.conversationSvc.DB(), result.Conversations, result.Count))
|
||||
c.JSON(http.StatusOK, serializeConversationSearchList(h.requestContext(c), h.conversationSvc.DB(), result.Conversations, result.Count))
|
||||
}
|
||||
|
||||
// Filter retrieves conversations matching advanced filter criteria.
|
||||
@@ -514,7 +525,7 @@ func (h *ConversationHandler) Filter(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
payload := serializeConversationList(c.Request.Context(), h.conversationSvc.DB(), result.Conversations, result.Count.AllCount)
|
||||
payload := serializeConversationList(h.requestContext(c), h.conversationSvc.DB(), result.Conversations, result.Count.AllCount)
|
||||
payload.Data.Meta = chatwootConversationCounts{
|
||||
MineCount: result.Count.MineCount,
|
||||
AssignedCount: result.Count.AssignedCount,
|
||||
@@ -555,7 +566,7 @@ func (h *ConversationHandler) UpdatePriority(c *gin.Context) {
|
||||
handleServiceError(c, svcErr)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, serializeConversation(c.Request.Context(), h.conversationSvc.DB(), conversation))
|
||||
c.JSON(http.StatusOK, serializeConversation(h.requestContext(c), h.conversationSvc.DB(), conversation))
|
||||
}
|
||||
|
||||
// TogglePriority updates a conversation priority using Chatwoot's member action path.
|
||||
@@ -685,7 +696,7 @@ func (h *ConversationHandler) Unread(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, serializeConversation(c.Request.Context(), h.conversationSvc.DB(), conversation))
|
||||
c.JSON(http.StatusOK, serializeConversation(h.requestContext(c), h.conversationSvc.DB(), conversation))
|
||||
}
|
||||
|
||||
// Transcript sends a conversation transcript via email.
|
||||
@@ -1008,7 +1019,7 @@ func (h *ConversationHandler) AssignTeam(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, serializeTeamFromDB(c.Request.Context(), h.conversationSvc.DB(), *req.TeamID, accountID))
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, serializeConversation(c.Request.Context(), h.conversationSvc.DB(), conversation))
|
||||
c.JSON(http.StatusOK, serializeConversation(h.requestContext(c), h.conversationSvc.DB(), conversation))
|
||||
}
|
||||
|
||||
// handleServiceError maps service-layer errors to appropriate HTTP responses.
|
||||
|
||||
Reference in New Issue
Block a user