39 lines
932 B
Go
39 lines
932 B
Go
|
|
package mapper
|
||
|
|
|
||
|
|
import (
|
||
|
|
"encoding/json"
|
||
|
|
"jaecoo-be/app/database/entity"
|
||
|
|
res "jaecoo-be/app/module/products/response"
|
||
|
|
)
|
||
|
|
|
||
|
|
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,
|
||
|
|
IsActive: product.IsActive,
|
||
|
|
CreatedAt: product.CreatedAt,
|
||
|
|
UpdatedAt: product.UpdatedAt,
|
||
|
|
}
|
||
|
|
|
||
|
|
if product.ThumbnailPath != nil && *product.ThumbnailPath != "" {
|
||
|
|
thumbnailUrl := host + "/products/thumbnail/viewer/" + *product.ThumbnailPath
|
||
|
|
response.ThumbnailUrl = &thumbnailUrl
|
||
|
|
}
|
||
|
|
|
||
|
|
return response
|
||
|
|
}
|
||
|
|
|