feat(reports): filter grouped live metrics by team
This commit is contained in:
@@ -31,14 +31,9 @@ func (h *LiveReportHandler) ConversationMetrics(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
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)
|
||||
teamID, ok := parseLiveReportTeamID(c)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
result, err := h.svc.GetConversationMetricsForTeam(c.Request.Context(), accountID, teamID)
|
||||
@@ -68,8 +63,12 @@ func (h *LiveReportHandler) GroupedConversationMetrics(c *gin.Context) {
|
||||
c.AbortWithStatusJSON(http.StatusUnprocessableEntity, gin.H{"error": "invalid group_by"})
|
||||
return
|
||||
}
|
||||
teamID, ok := parseLiveReportTeamID(c)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
result, err := h.svc.GetGroupedConversationMetrics(c.Request.Context(), accountID, groupBy)
|
||||
result, err := h.svc.GetGroupedConversationMetricsForTeam(c.Request.Context(), accountID, groupBy, teamID)
|
||||
if err != nil {
|
||||
applogger.L().Errorf("Grouped conversation metrics: %v", err)
|
||||
response.AbortWithStatusError(c, http.StatusInternalServerError, response.ErrInternal, "failed to get grouped conversation metrics")
|
||||
@@ -78,3 +77,16 @@ func (h *LiveReportHandler) GroupedConversationMetrics(c *gin.Context) {
|
||||
|
||||
c.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
func parseLiveReportTeamID(c *gin.Context) (uint, bool) {
|
||||
teamIDStr := c.Query("team_id")
|
||||
if teamIDStr == "" {
|
||||
return 0, true
|
||||
}
|
||||
parsed, err := strconv.ParseUint(teamIDStr, 10, 64)
|
||||
if err != nil {
|
||||
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid team_id")
|
||||
return 0, false
|
||||
}
|
||||
return uint(parsed), true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user