Fix product performance grouped JSON build
This commit is contained in:
@@ -593,6 +593,23 @@ func resolveStoragePath(storagePath string) (string, []string) {
|
||||
filepath.Join("..", "..", relImageThumb),
|
||||
}
|
||||
|
||||
if u := extractImageUUID(raw, baseName); u != "" {
|
||||
uFull := filepath.FromSlash(filepath.Join("uploads", "image", u+".jpg"))
|
||||
uThumb := filepath.FromSlash(filepath.Join("uploads", "image", "t300", u+".jpg"))
|
||||
candidates = append(candidates,
|
||||
filepath.FromSlash(filepath.Join("image", u+".jpg")),
|
||||
filepath.FromSlash(filepath.Join("image", "t300", u+".jpg")),
|
||||
uFull,
|
||||
uThumb,
|
||||
filepath.Join(".", uFull),
|
||||
filepath.Join(".", uThumb),
|
||||
filepath.Join("..", uFull),
|
||||
filepath.Join("..", uThumb),
|
||||
filepath.Join("..", "..", uFull),
|
||||
filepath.Join("..", "..", uThumb),
|
||||
)
|
||||
}
|
||||
|
||||
if root := strings.TrimSpace(os.Getenv("BLOB_ROOT")); root != "" {
|
||||
candidates = append(candidates,
|
||||
filepath.Join(root, raw),
|
||||
@@ -601,6 +618,14 @@ func resolveStoragePath(storagePath string) (string, []string) {
|
||||
filepath.Join(root, relImage),
|
||||
filepath.Join(root, relImageThumb),
|
||||
)
|
||||
if u := extractImageUUID(raw, baseName); u != "" {
|
||||
candidates = append(candidates,
|
||||
filepath.Join(root, "uploads", "image", u+".jpg"),
|
||||
filepath.Join(root, "uploads", "image", "t300", u+".jpg"),
|
||||
filepath.Join(root, "image", u+".jpg"),
|
||||
filepath.Join(root, "image", "t300", u+".jpg"),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
for _, p := range candidates {
|
||||
|
||||
@@ -359,6 +359,64 @@ func GetProductPerformanceGroupedHandler(pg *sql.DB) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func GetProductPerformanceGroupedFilterOptionsHandler(pg *sql.DB) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
traceID := utils.TraceIDFromRequest(r)
|
||||
ctx, cancel := context.WithTimeout(utils.ContextWithTraceID(r.Context(), traceID), 60*time.Second)
|
||||
defer cancel()
|
||||
|
||||
mode := strings.TrimSpace(r.URL.Query().Get("mode"))
|
||||
mainGroup := strings.TrimSpace(r.URL.Query().Get("urun_ana_grubu"))
|
||||
groupLevels := splitCSVQuery(r.URL.Query().Get("group_levels"))
|
||||
fields := splitCSVQuery(r.URL.Query().Get("fields"))
|
||||
limit := intQuery(r, "limit", 5000)
|
||||
|
||||
if r.Method == http.MethodPost {
|
||||
var body struct {
|
||||
Mode string `json:"mode"`
|
||||
GroupLevels []string `json:"group_levels"`
|
||||
MainGroup string `json:"urun_ana_grubu"`
|
||||
Fields []string `json:"fields"`
|
||||
Limit int `json:"limit"`
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||
http.Error(w, "gecersiz filtre secenek istegi: "+err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if strings.TrimSpace(body.Mode) != "" {
|
||||
mode = strings.TrimSpace(body.Mode)
|
||||
}
|
||||
if strings.TrimSpace(body.MainGroup) != "" {
|
||||
mainGroup = strings.TrimSpace(body.MainGroup)
|
||||
}
|
||||
if len(body.GroupLevels) > 0 {
|
||||
groupLevels = body.GroupLevels
|
||||
}
|
||||
if len(body.Fields) > 0 {
|
||||
fields = body.Fields
|
||||
}
|
||||
if body.Limit > 0 {
|
||||
limit = body.Limit
|
||||
}
|
||||
}
|
||||
|
||||
options, err := queries.ListProductPerformanceGroupedFilterOptions(ctx, pg, queries.ProductPerformanceGroupedFilterOptionsRequest{
|
||||
Mode: mode,
|
||||
GroupLevels: groupLevels,
|
||||
MainGroup: mainGroup,
|
||||
Fields: fields,
|
||||
Limit: limit,
|
||||
})
|
||||
if err != nil {
|
||||
log.Printf("[ProductPerformance][grouped-filter-options] failed trace_id=%s mode=%s levels=%v fields=%d: %v", traceID, mode, groupLevels, len(fields), err)
|
||||
http.Error(w, "urun performans filtre secenekleri alinamadi: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
_ = json.NewEncoder(w).Encode(options)
|
||||
}
|
||||
}
|
||||
|
||||
func splitCSVQuery(value string) []string {
|
||||
parts := strings.Split(value, ",")
|
||||
out := make([]string, 0, len(parts))
|
||||
|
||||
Reference in New Issue
Block a user