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 {
|
||||
color = strings.ToUpper(strings.TrimSpace(color))
|
||||
secondColor = strings.ToUpper(strings.TrimSpace(secondColor))
|
||||
if color == "" && secondColor == "" {
|
||||
func imageFileMatches(fileName, dim1, dim3 string) bool {
|
||||
dim1 = strings.ToUpper(strings.TrimSpace(dim1))
|
||||
dim3 = strings.ToUpper(strings.TrimSpace(dim3))
|
||||
if dim1 == "" && dim3 == "" {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -62,14 +62,14 @@ func imageFileMatches(fileName, color, secondColor string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
return hasToken(color) && hasToken(secondColor)
|
||||
return hasToken(dim1) && hasToken(dim3)
|
||||
}
|
||||
|
||||
//
|
||||
// LIST PRODUCT IMAGES
|
||||
//
|
||||
|
||||
// GET /api/product-images?code=...&color=...&yaka=...
|
||||
// GET /api/product-images?code=...&dim1=...&dim3=...
|
||||
func GetProductImagesHandler(pg *sql.DB) http.HandlerFunc {
|
||||
|
||||
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)
|
||||
|
||||
code := strings.TrimSpace(r.URL.Query().Get("code"))
|
||||
color := strings.TrimSpace(r.URL.Query().Get("color"))
|
||||
secondColor := strings.TrimSpace(r.URL.Query().Get("yaka"))
|
||||
if secondColor == "" {
|
||||
secondColor = strings.TrimSpace(r.URL.Query().Get("renk2"))
|
||||
dim1 := strings.TrimSpace(r.URL.Query().Get("dim1"))
|
||||
if dim1 == "" {
|
||||
dim1 = strings.TrimSpace(r.URL.Query().Get("color"))
|
||||
}
|
||||
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 == "" {
|
||||
@@ -106,28 +112,35 @@ SELECT
|
||||
b.id,
|
||||
b.file_name,
|
||||
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
|
||||
JOIN mmitem i
|
||||
ON i.id = b.src_id
|
||||
WHERE b.typ = 'img'
|
||||
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
|
||||
COALESCE(b.sort_order,999999),
|
||||
b.zlins_dttm DESC,
|
||||
b.id DESC
|
||||
`
|
||||
|
||||
rows, err := pg.Query(query, code)
|
||||
rows, err := pg.Query(query, code, dim1, dim3)
|
||||
|
||||
if err != nil {
|
||||
|
||||
slog.Error("product_images.list.query_failed",
|
||||
"req_id", reqID,
|
||||
"code", code,
|
||||
"color", color,
|
||||
"second_color", secondColor,
|
||||
"dim1", dim1,
|
||||
"dim3", dim3,
|
||||
"err", err.Error(),
|
||||
)
|
||||
|
||||
@@ -138,33 +151,70 @@ ORDER BY
|
||||
defer rows.Close()
|
||||
|
||||
items := make([]ProductImageItem, 0, 16)
|
||||
matchedByDim := make([]ProductImageItem, 0, 16)
|
||||
matchedByName := make([]ProductImageItem, 0, 16)
|
||||
matchedByNameDim1Only := make([]ProductImageItem, 0, 16)
|
||||
|
||||
for rows.Next() {
|
||||
|
||||
var it ProductImageItem
|
||||
var rowDim1, rowDim2, rowDim3 string
|
||||
|
||||
if err := rows.Scan(
|
||||
&it.ID,
|
||||
&it.FileName,
|
||||
&it.FileSize,
|
||||
&it.Storage,
|
||||
&rowDim1,
|
||||
&rowDim2,
|
||||
&rowDim3,
|
||||
); err != nil {
|
||||
continue
|
||||
}
|
||||
if !imageFileMatches(it.FileName, color, secondColor) {
|
||||
continue
|
||||
}
|
||||
|
||||
it.ContentURL = fmt.Sprintf("/api/product-images/%d/content", it.ID)
|
||||
|
||||
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",
|
||||
"req_id", reqID,
|
||||
"code", code,
|
||||
"color", color,
|
||||
"second_color", secondColor,
|
||||
"dim1", dim1,
|
||||
"dim3", dim3,
|
||||
"count", len(items),
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user