fix
This commit is contained in:
parent
13b95c0109
commit
42e856f068
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"jaecoo-be/app/database/entity"
|
"jaecoo-be/app/database/entity"
|
||||||
res "jaecoo-be/app/module/products/response"
|
res "jaecoo-be/app/module/products/response"
|
||||||
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ProductsResponseMapper(product *entity.Products, host string) *res.ProductsResponse {
|
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 {
|
for _, c := range rawColors {
|
||||||
var imageUrl *string
|
var imageUrl *string
|
||||||
|
|
||||||
if c.ImagePath != nil && *c.ImagePath != "" {
|
if c.ImagePath != nil {
|
||||||
url := host + "/api/products/viewer/" + *c.ImagePath
|
filename := filepath.Base(*c.ImagePath)
|
||||||
|
url := host + "/products/viewer/" + filename
|
||||||
imageUrl = &url
|
imageUrl = &url
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
colors = append(colors, res.ProductColorResponse{
|
colors = append(colors, res.ProductColorResponse{
|
||||||
|
|
@ -37,6 +40,7 @@ func ProductsResponseMapper(product *entity.Products, host string) *res.Products
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
response := &res.ProductsResponse{
|
response := &res.ProductsResponse{
|
||||||
ID: product.ID,
|
ID: product.ID,
|
||||||
Title: product.Title,
|
Title: product.Title,
|
||||||
|
|
@ -52,11 +56,12 @@ func ProductsResponseMapper(product *entity.Products, host string) *res.Products
|
||||||
}
|
}
|
||||||
|
|
||||||
if product.ThumbnailPath != nil && *product.ThumbnailPath != "" {
|
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
|
response.ThumbnailUrl = &thumbnailUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue