This commit is contained in:
Anang Yusman 2026-01-27 18:32:47 +08:00
parent 13b95c0109
commit 42e856f068
1 changed files with 29 additions and 24 deletions

View File

@ -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 {
@ -24,9 +25,11 @@ func ProductsResponseMapper(product *entity.Products, host string) *res.Products
for _, c := range rawColors {
var imageUrl *string
if c.ImagePath != nil && *c.ImagePath != "" {
url := host + "/api/products/viewer/" + *c.ImagePath
if c.ImagePath != nil {
filename := filepath.Base(*c.ImagePath)
url := host + "/products/viewer/" + filename
imageUrl = &url
}
colors = append(colors, res.ProductColorResponse{
@ -37,6 +40,7 @@ func ProductsResponseMapper(product *entity.Products, host string) *res.Products
}
}
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
}