product performance grouped kpi improvements

This commit is contained in:
M_Kececi
2026-07-03 01:53:00 +03:00
parent be6feb8aa8
commit a0d06b5fcf
6 changed files with 794 additions and 126 deletions
+38 -7
View File
@@ -268,19 +268,50 @@ func GetProductPerformanceGroupedHandler(pg *sql.DB) http.HandlerFunc {
ctx, cancel := context.WithTimeout(utils.ContextWithTraceID(r.Context(), traceID), 90*time.Second)
defer cancel()
mode := strings.TrimSpace(r.URL.Query().Get("mode"))
groupLevels := splitCSVQuery(r.URL.Query().Get("group_levels"))
limit := intQuery(r, "limit", 50000)
expanded := map[string]bool{}
for _, key := range strings.Split(r.URL.Query().Get("expanded_keys"), ",") {
key = strings.TrimSpace(key)
if key != "" {
expanded[key] = true
if r.Method == http.MethodPost {
var body struct {
Mode string `json:"mode"`
GroupLevels []string `json:"group_levels"`
ExpandedKeys []string `json:"expanded_keys"`
Limit int `json:"limit"`
}
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
http.Error(w, "gecersiz grup istegi: "+err.Error(), http.StatusBadRequest)
return
}
if strings.TrimSpace(body.Mode) != "" {
mode = strings.TrimSpace(body.Mode)
}
if len(body.GroupLevels) > 0 {
groupLevels = body.GroupLevels
}
if body.Limit > 0 {
limit = body.Limit
}
for _, key := range body.ExpandedKeys {
key = strings.TrimSpace(key)
if key != "" {
expanded[key] = true
}
}
} else {
for _, key := range strings.Split(r.URL.Query().Get("expanded_keys"), ",") {
key = strings.TrimSpace(key)
if key != "" {
expanded[key] = true
}
}
}
rows, err := queries.ListProductPerformanceGrouped(ctx, pg, queries.ProductPerformanceGroupedRequest{
Mode: strings.TrimSpace(r.URL.Query().Get("mode")),
GroupLevels: splitCSVQuery(r.URL.Query().Get("group_levels")),
Mode: mode,
GroupLevels: groupLevels,
ExpandedKeys: expanded,
Limit: intQuery(r, "limit", 50000),
Limit: limit,
})
if err != nil {
http.Error(w, "urun performans grup verisi alinamadi: "+err.Error(), http.StatusInternalServerError)