feat(reports): derive analytics aggregates

This commit is contained in:
2026-06-05 20:53:30 +08:00
parent 37bdac422a
commit a48b9cda8e
8 changed files with 726 additions and 72 deletions
+12 -7
View File
@@ -2,6 +2,7 @@ package v1
import (
"net/http"
"strconv"
"github.com/gin-gonic/gin"
@@ -30,19 +31,23 @@ func (h *LiveReportHandler) ConversationMetrics(c *gin.Context) {
return
}
// Chatwoot supports team_id filter
teamIDStr := c.Query("team_id")
teamID := uint(0)
if teamIDStr := c.Query("team_id"); teamIDStr != "" {
parsed, err := strconv.ParseUint(teamIDStr, 10, 64)
if err != nil {
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid team_id")
return
}
teamID = uint(parsed)
}
result, err := h.svc.GetConversationMetrics(c.Request.Context(), accountID)
result, err := h.svc.GetConversationMetricsForTeam(c.Request.Context(), accountID, teamID)
if err != nil {
applogger.L().Errorf("Live conversation metrics: %v", err)
response.AbortWithStatusError(c, http.StatusInternalServerError, response.ErrInternal, "failed to get conversation metrics")
return
}
// Chatwoot also filters by team_id if provided — TODO: implement team filter
_ = teamIDStr
response.OK(c, result)
}
@@ -72,4 +77,4 @@ func (h *LiveReportHandler) GroupedConversationMetrics(c *gin.Context) {
}
response.OK(c, result)
}
}