From 42e856f068ba84b4bfbc755e066ffff101368470 Mon Sep 17 00:00:00 2001 From: Anang Yusman Date: Tue, 27 Jan 2026 18:32:47 +0800 Subject: [PATCH] fix --- app/module/products/mapper/products.mapper.go | 53 ++++++++++--------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/app/module/products/mapper/products.mapper.go b/app/module/products/mapper/products.mapper.go index 4f3df2d..eed5080 100644 --- a/app/module/products/mapper/products.mapper.go +++ b/app/module/products/mapper/products.mapper.go @@ -4,6 +4,7 @@ import ( "encoding/json" "jaecoo-be/app/database/entity" res "jaecoo-be/app/module/products/response" + "path/filepath" ) func ProductsResponseMapper(product *entity.Products, host string) *res.ProductsResponse { @@ -13,30 +14,33 @@ func ProductsResponseMapper(product *entity.Products, host string) *res.Products var colors []res.ProductColorResponse - if product.Colors != nil && *product.Colors != "" { - var rawColors []struct { - Name string `json:"name"` - ImagePath *string `json:"image_path"` - } - - _ = json.Unmarshal([]byte(*product.Colors), &rawColors) - - for _, c := range rawColors { - var imageUrl *string - - if c.ImagePath != nil && *c.ImagePath != "" { - url := host + "/api/products/viewer/" + *c.ImagePath - imageUrl = &url - } - - colors = append(colors, res.ProductColorResponse{ - Name: c.Name, - ImagePath: c.ImagePath, - ImageUrl: imageUrl, - }) - } +if product.Colors != nil && *product.Colors != "" { + var rawColors []struct { + Name string `json:"name"` + ImagePath *string `json:"image_path"` } + _ = json.Unmarshal([]byte(*product.Colors), &rawColors) + + for _, c := range rawColors { + var imageUrl *string + + if c.ImagePath != nil { + filename := filepath.Base(*c.ImagePath) + url := host + "/products/viewer/" + filename + imageUrl = &url + + } + + colors = append(colors, res.ProductColorResponse{ + Name: c.Name, + ImagePath: c.ImagePath, + ImageUrl: imageUrl, + }) + } +} + + response := &res.ProductsResponse{ ID: product.ID, Title: product.Title, @@ -52,11 +56,12 @@ func ProductsResponseMapper(product *entity.Products, host string) *res.Products } if product.ThumbnailPath != nil && *product.ThumbnailPath != "" { - thumbnailUrl := host + "/api/products/viewer/" + *product.ThumbnailPath + // Extract filename from path + filename := filepath.Base(*product.ThumbnailPath) + thumbnailUrl := host + "/products/viewer/" + filename response.ThumbnailUrl = &thumbnailUrl } return response } -