Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -38,10 +38,10 @@ func tokenizeImageFileName(fileName string) []string {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func imageFileMatches(fileName, color, secondColor string) bool {
|
func imageFileMatches(fileName, dim1, dim3 string) bool {
|
||||||
color = strings.ToUpper(strings.TrimSpace(color))
|
dim1 = strings.ToUpper(strings.TrimSpace(dim1))
|
||||||
secondColor = strings.ToUpper(strings.TrimSpace(secondColor))
|
dim3 = strings.ToUpper(strings.TrimSpace(dim3))
|
||||||
if color == "" && secondColor == "" {
|
if dim1 == "" && dim3 == "" {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,14 +62,14 @@ func imageFileMatches(fileName, color, secondColor string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return hasToken(color) && hasToken(secondColor)
|
return hasToken(dim1) && hasToken(dim3)
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// LIST PRODUCT IMAGES
|
// LIST PRODUCT IMAGES
|
||||||
//
|
//
|
||||||
|
|
||||||
// GET /api/product-images?code=...&color=...&yaka=...
|
// GET /api/product-images?code=...&dim1=...&dim3=...
|
||||||
func GetProductImagesHandler(pg *sql.DB) http.HandlerFunc {
|
func GetProductImagesHandler(pg *sql.DB) http.HandlerFunc {
|
||||||
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -82,10 +82,16 @@ func GetProductImagesHandler(pg *sql.DB) http.HandlerFunc {
|
|||||||
w.Header().Set("X-Request-ID", reqID)
|
w.Header().Set("X-Request-ID", reqID)
|
||||||
|
|
||||||
code := strings.TrimSpace(r.URL.Query().Get("code"))
|
code := strings.TrimSpace(r.URL.Query().Get("code"))
|
||||||
color := strings.TrimSpace(r.URL.Query().Get("color"))
|
dim1 := strings.TrimSpace(r.URL.Query().Get("dim1"))
|
||||||
secondColor := strings.TrimSpace(r.URL.Query().Get("yaka"))
|
if dim1 == "" {
|
||||||
if secondColor == "" {
|
dim1 = strings.TrimSpace(r.URL.Query().Get("color"))
|
||||||
secondColor = strings.TrimSpace(r.URL.Query().Get("renk2"))
|
}
|
||||||
|
dim3 := strings.TrimSpace(r.URL.Query().Get("dim3"))
|
||||||
|
if dim3 == "" {
|
||||||
|
dim3 = strings.TrimSpace(r.URL.Query().Get("yaka"))
|
||||||
|
}
|
||||||
|
if dim3 == "" {
|
||||||
|
dim3 = strings.TrimSpace(r.URL.Query().Get("renk2"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if code == "" {
|
if code == "" {
|
||||||
@@ -106,28 +112,35 @@ SELECT
|
|||||||
b.id,
|
b.id,
|
||||||
b.file_name,
|
b.file_name,
|
||||||
COALESCE(b.file_size,0) AS file_size,
|
COALESCE(b.file_size,0) AS file_size,
|
||||||
COALESCE(b.storage_path,'') AS storage_path
|
COALESCE(b.storage_path,'') AS storage_path,
|
||||||
|
UPPER(COALESCE(b.dimval1,'')) AS dimval1,
|
||||||
|
UPPER(COALESCE(b.dimval2,'')) AS dimval2,
|
||||||
|
UPPER(COALESCE(b.dimval3,'')) AS dimval3
|
||||||
FROM dfblob b
|
FROM dfblob b
|
||||||
JOIN mmitem i
|
JOIN mmitem i
|
||||||
ON i.id = b.src_id
|
ON i.id = b.src_id
|
||||||
WHERE b.typ = 'img'
|
WHERE b.typ = 'img'
|
||||||
AND b.src_table = 'mmitem'
|
AND b.src_table = 'mmitem'
|
||||||
AND UPPER(i.code) = UPPER($1)
|
AND (
|
||||||
|
UPPER(i.code) = UPPER($1)
|
||||||
|
OR UPPER(i.code) = UPPER('S001-' || $1)
|
||||||
|
OR UPPER(i.code) LIKE '%-' || UPPER($1)
|
||||||
|
)
|
||||||
ORDER BY
|
ORDER BY
|
||||||
COALESCE(b.sort_order,999999),
|
COALESCE(b.sort_order,999999),
|
||||||
b.zlins_dttm DESC,
|
b.zlins_dttm DESC,
|
||||||
b.id DESC
|
b.id DESC
|
||||||
`
|
`
|
||||||
|
|
||||||
rows, err := pg.Query(query, code)
|
rows, err := pg.Query(query, code, dim1, dim3)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
slog.Error("product_images.list.query_failed",
|
slog.Error("product_images.list.query_failed",
|
||||||
"req_id", reqID,
|
"req_id", reqID,
|
||||||
"code", code,
|
"code", code,
|
||||||
"color", color,
|
"dim1", dim1,
|
||||||
"second_color", secondColor,
|
"dim3", dim3,
|
||||||
"err", err.Error(),
|
"err", err.Error(),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -138,33 +151,70 @@ ORDER BY
|
|||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
items := make([]ProductImageItem, 0, 16)
|
items := make([]ProductImageItem, 0, 16)
|
||||||
|
matchedByDim := make([]ProductImageItem, 0, 16)
|
||||||
|
matchedByName := make([]ProductImageItem, 0, 16)
|
||||||
|
matchedByNameDim1Only := make([]ProductImageItem, 0, 16)
|
||||||
|
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
|
|
||||||
var it ProductImageItem
|
var it ProductImageItem
|
||||||
|
var rowDim1, rowDim2, rowDim3 string
|
||||||
|
|
||||||
if err := rows.Scan(
|
if err := rows.Scan(
|
||||||
&it.ID,
|
&it.ID,
|
||||||
&it.FileName,
|
&it.FileName,
|
||||||
&it.FileSize,
|
&it.FileSize,
|
||||||
&it.Storage,
|
&it.Storage,
|
||||||
|
&rowDim1,
|
||||||
|
&rowDim2,
|
||||||
|
&rowDim3,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !imageFileMatches(it.FileName, color, secondColor) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
it.ContentURL = fmt.Sprintf("/api/product-images/%d/content", it.ID)
|
it.ContentURL = fmt.Sprintf("/api/product-images/%d/content", it.ID)
|
||||||
|
|
||||||
items = append(items, it)
|
items = append(items, it)
|
||||||
|
|
||||||
|
dimMatched := true
|
||||||
|
if dim1 != "" {
|
||||||
|
// Bazı eski kayıtlarda dimval1 gerçek renk kodu yerine numeric id tutulmuş olabilir.
|
||||||
|
// Bu yüzden dimval karşılaştırması yardımcı; asıl fallback file_name token eşleşmesidir.
|
||||||
|
dimMatched = dimMatched && (rowDim1 == strings.ToUpper(dim1))
|
||||||
|
}
|
||||||
|
if dim3 != "" {
|
||||||
|
dimMatched = dimMatched && (rowDim3 == strings.ToUpper(dim3) || rowDim2 == strings.ToUpper(dim3))
|
||||||
|
}
|
||||||
|
if dimMatched {
|
||||||
|
matchedByDim = append(matchedByDim, it)
|
||||||
|
}
|
||||||
|
|
||||||
|
if imageFileMatches(it.FileName, dim1, dim3) {
|
||||||
|
matchedByName = append(matchedByName, it)
|
||||||
|
}
|
||||||
|
if dim1 != "" && imageFileMatches(it.FileName, dim1, "") {
|
||||||
|
matchedByNameDim1Only = append(matchedByNameDim1Only, it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if dim1 != "" || dim3 != "" {
|
||||||
|
if len(matchedByDim) > 0 {
|
||||||
|
items = matchedByDim
|
||||||
|
} else if len(matchedByName) > 0 {
|
||||||
|
items = matchedByName
|
||||||
|
} else if len(matchedByNameDim1Only) > 0 {
|
||||||
|
// dim3 eski/uyumsuz kayitlarda tutulmuyorsa en azindan 1.renk ile daralt.
|
||||||
|
items = matchedByNameDim1Only
|
||||||
|
} else {
|
||||||
|
// Filtre verildi ama eslesme yoksa tum listeyi donmeyelim.
|
||||||
|
items = []ProductImageItem{}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
slog.Info("product_images.list.ok",
|
slog.Info("product_images.list.ok",
|
||||||
"req_id", reqID,
|
"req_id", reqID,
|
||||||
"code", code,
|
"code", code,
|
||||||
"color", color,
|
"dim1", dim1,
|
||||||
"second_color", secondColor,
|
"dim3", dim3,
|
||||||
"count", len(items),
|
"count", len(items),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user