2025-11-15 17:43:23 +00:00
|
|
|
package mapper
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"jaecoo-be/app/database/entity"
|
|
|
|
|
res "jaecoo-be/app/module/products/response"
|
2025-11-17 15:44:55 +00:00
|
|
|
"path/filepath"
|
2025-11-15 17:43:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func ProductsResponseMapper(product *entity.Products, host string) *res.ProductsResponse {
|
|
|
|
|
if product == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var colors []string
|
|
|
|
|
if product.Colors != nil && *product.Colors != "" {
|
|
|
|
|
json.Unmarshal([]byte(*product.Colors), &colors)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response := &res.ProductsResponse{
|
|
|
|
|
ID: product.ID,
|
|
|
|
|
Title: product.Title,
|
|
|
|
|
Variant: product.Variant,
|
|
|
|
|
Price: product.Price,
|
|
|
|
|
ThumbnailPath: product.ThumbnailPath,
|
|
|
|
|
Colors: colors,
|
2026-01-19 15:35:19 +00:00
|
|
|
Status: product.Status,
|
2026-01-20 01:08:14 +00:00
|
|
|
StatusId: product.StatusId,
|
2025-11-15 17:43:23 +00:00
|
|
|
IsActive: product.IsActive,
|
|
|
|
|
CreatedAt: product.CreatedAt,
|
|
|
|
|
UpdatedAt: product.UpdatedAt,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if product.ThumbnailPath != nil && *product.ThumbnailPath != "" {
|
2025-11-17 15:44:55 +00:00
|
|
|
// Extract filename from path
|
|
|
|
|
filename := filepath.Base(*product.ThumbnailPath)
|
|
|
|
|
thumbnailUrl := host + "/products/viewer/" + filename
|
2025-11-15 17:43:23 +00:00
|
|
|
response.ThumbnailUrl = &thumbnailUrl
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return response
|
|
|
|
|
}
|
|
|
|
|
|