Fix product performance grouped JSON build
This commit is contained in:
@@ -141,18 +141,14 @@ func enrichProductImageItem(it *ProductImageItem) {
|
||||
if it == nil {
|
||||
return
|
||||
}
|
||||
if it.ID > 0 {
|
||||
it.ContentURL = fmt.Sprintf("/api/product-images/%d/content", it.ID)
|
||||
}
|
||||
if u := extractImageUUID(it.Storage, it.FileName); u != "" {
|
||||
it.UUID = u
|
||||
it.ThumbURL = "/uploads/image/t300/" + u + ".jpg"
|
||||
it.FullURL = "/uploads/image/" + u + ".jpg"
|
||||
}
|
||||
if it.StoredInDB {
|
||||
it.ContentURL = fmt.Sprintf("/api/product-images/%d/content", it.ID)
|
||||
return
|
||||
}
|
||||
if resolved, _ := resolveStoragePath(it.Storage); resolved != "" {
|
||||
it.ContentURL = fmt.Sprintf("/api/product-images/%d/content", it.ID)
|
||||
}
|
||||
}
|
||||
|
||||
// POST /api/product-images/batch
|
||||
@@ -576,14 +572,25 @@ func resolveStoragePath(storagePath string) (string, []string) {
|
||||
raw = filepath.ToSlash(filepath.Clean(raw))
|
||||
|
||||
relUploads := filepath.FromSlash(filepath.Join("uploads", raw))
|
||||
baseName := filepath.Base(raw)
|
||||
relImage := filepath.FromSlash(filepath.Join("uploads", "image", baseName))
|
||||
relImageThumb := filepath.FromSlash(filepath.Join("uploads", "image", "t300", baseName))
|
||||
candidates := []string{
|
||||
filepath.Clean(storagePath),
|
||||
filepath.FromSlash(filepath.Clean(strings.TrimPrefix(storagePath, "/"))),
|
||||
filepath.FromSlash(filepath.Clean(raw)),
|
||||
relUploads,
|
||||
relImage,
|
||||
relImageThumb,
|
||||
filepath.Join(".", relUploads),
|
||||
filepath.Join(".", relImage),
|
||||
filepath.Join(".", relImageThumb),
|
||||
filepath.Join("..", relUploads),
|
||||
filepath.Join("..", relImage),
|
||||
filepath.Join("..", relImageThumb),
|
||||
filepath.Join("..", "..", relUploads),
|
||||
filepath.Join("..", "..", relImage),
|
||||
filepath.Join("..", "..", relImageThumb),
|
||||
}
|
||||
|
||||
if root := strings.TrimSpace(os.Getenv("BLOB_ROOT")); root != "" {
|
||||
@@ -591,6 +598,8 @@ func resolveStoragePath(storagePath string) (string, []string) {
|
||||
filepath.Join(root, raw),
|
||||
filepath.Join(root, relUploads),
|
||||
filepath.Join(root, "uploads", raw),
|
||||
filepath.Join(root, relImage),
|
||||
filepath.Join(root, relImageThumb),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -273,7 +273,14 @@ func GetProductPerformanceGroupedHandler(pg *sql.DB) http.HandlerFunc {
|
||||
groupLevels := splitCSVQuery(r.URL.Query().Get("group_levels"))
|
||||
limit := intQuery(r, "limit", 50000)
|
||||
expanded := map[string]bool{}
|
||||
const maxExpandedGroupKeys = 260
|
||||
filters := map[string][]string{}
|
||||
expandThroughLevel := -1
|
||||
if rawExpandLevel := strings.TrimSpace(r.URL.Query().Get("expand_through_level")); rawExpandLevel != "" {
|
||||
if parsed, err := strconv.Atoi(rawExpandLevel); err == nil {
|
||||
expandThroughLevel = parsed
|
||||
}
|
||||
}
|
||||
const maxExpandedGroupKeys = 1000
|
||||
addExpandedKey := func(key string) {
|
||||
key = strings.TrimSpace(key)
|
||||
if key != "" && len(expanded) < maxExpandedGroupKeys {
|
||||
@@ -282,11 +289,13 @@ func GetProductPerformanceGroupedHandler(pg *sql.DB) http.HandlerFunc {
|
||||
}
|
||||
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"`
|
||||
MainGroup string `json:"urun_ana_grubu"`
|
||||
Mode string `json:"mode"`
|
||||
GroupLevels []string `json:"group_levels"`
|
||||
ExpandedKeys []string `json:"expanded_keys"`
|
||||
ExpandThroughLevel *int `json:"expand_through_level"`
|
||||
Limit int `json:"limit"`
|
||||
MainGroup string `json:"urun_ana_grubu"`
|
||||
Filters map[string][]string `json:"filters"`
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||
http.Error(w, "gecersiz grup istegi: "+err.Error(), http.StatusBadRequest)
|
||||
@@ -307,6 +316,12 @@ func GetProductPerformanceGroupedHandler(pg *sql.DB) http.HandlerFunc {
|
||||
for _, key := range body.ExpandedKeys {
|
||||
addExpandedKey(key)
|
||||
}
|
||||
if body.ExpandThroughLevel != nil {
|
||||
expandThroughLevel = *body.ExpandThroughLevel
|
||||
}
|
||||
if len(body.Filters) > 0 {
|
||||
filters = body.Filters
|
||||
}
|
||||
} else {
|
||||
for _, key := range strings.Split(r.URL.Query().Get("expanded_keys"), ",") {
|
||||
addExpandedKey(key)
|
||||
@@ -314,11 +329,13 @@ func GetProductPerformanceGroupedHandler(pg *sql.DB) http.HandlerFunc {
|
||||
}
|
||||
|
||||
rows, err := queries.ListProductPerformanceGrouped(ctx, pg, queries.ProductPerformanceGroupedRequest{
|
||||
Mode: mode,
|
||||
GroupLevels: groupLevels,
|
||||
ExpandedKeys: expanded,
|
||||
Limit: limit,
|
||||
MainGroup: mainGroup,
|
||||
Mode: mode,
|
||||
GroupLevels: groupLevels,
|
||||
ExpandedKeys: expanded,
|
||||
ExpandThroughLevel: expandThroughLevel,
|
||||
Limit: limit,
|
||||
MainGroup: mainGroup,
|
||||
Filters: filters,
|
||||
})
|
||||
if err != nil {
|
||||
http.Error(w, "urun performans grup verisi alinamadi: "+err.Error(), http.StatusInternalServerError)
|
||||
|
||||
Reference in New Issue
Block a user