Fix product performance grouped JSON build
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -270,6 +271,8 @@ func GetProductPerformanceGroupedHandler(pg *sql.DB) http.HandlerFunc {
|
||||
|
||||
mode := strings.TrimSpace(r.URL.Query().Get("mode"))
|
||||
mainGroup := strings.TrimSpace(r.URL.Query().Get("urun_ana_grubu"))
|
||||
sortBy := strings.TrimSpace(r.URL.Query().Get("sort_by"))
|
||||
descending := boolQuery(r, "descending", true)
|
||||
groupLevels := splitCSVQuery(r.URL.Query().Get("group_levels"))
|
||||
limit := intQuery(r, "limit", 50000)
|
||||
expanded := map[string]bool{}
|
||||
@@ -296,6 +299,8 @@ func GetProductPerformanceGroupedHandler(pg *sql.DB) http.HandlerFunc {
|
||||
Limit int `json:"limit"`
|
||||
MainGroup string `json:"urun_ana_grubu"`
|
||||
Filters map[string][]string `json:"filters"`
|
||||
SortBy string `json:"sort_by"`
|
||||
Descending *bool `json:"descending"`
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||
http.Error(w, "gecersiz grup istegi: "+err.Error(), http.StatusBadRequest)
|
||||
@@ -322,6 +327,12 @@ func GetProductPerformanceGroupedHandler(pg *sql.DB) http.HandlerFunc {
|
||||
if len(body.Filters) > 0 {
|
||||
filters = body.Filters
|
||||
}
|
||||
if strings.TrimSpace(body.SortBy) != "" {
|
||||
sortBy = strings.TrimSpace(body.SortBy)
|
||||
}
|
||||
if body.Descending != nil {
|
||||
descending = *body.Descending
|
||||
}
|
||||
} else {
|
||||
for _, key := range strings.Split(r.URL.Query().Get("expanded_keys"), ",") {
|
||||
addExpandedKey(key)
|
||||
@@ -336,8 +347,11 @@ func GetProductPerformanceGroupedHandler(pg *sql.DB) http.HandlerFunc {
|
||||
Limit: limit,
|
||||
MainGroup: mainGroup,
|
||||
Filters: filters,
|
||||
SortBy: sortBy,
|
||||
Descending: descending,
|
||||
})
|
||||
if err != nil {
|
||||
log.Printf("[ProductPerformance][grouped] failed trace_id=%s mode=%s levels=%v expand_through_level=%d filters=%d: %v", traceID, mode, groupLevels, expandThroughLevel, len(filters), err)
|
||||
http.Error(w, "urun performans grup verisi alinamadi: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user