fix
This commit is contained in:
parent
13b95c0109
commit
42e856f068
|
|
@ -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
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue