jaecoo-be/app/module/product_specifications/mapper/product_specifications.mapp...

34 lines
852 B
Go
Raw Permalink Normal View History

2025-11-15 17:43:23 +00:00
package mapper
import (
"jaecoo-be/app/database/entity"
res "jaecoo-be/app/module/product_specifications/response"
"path/filepath"
2025-11-15 17:43:23 +00:00
)
func ProductSpecificationsResponseMapper(spec *entity.ProductSpecifications, host string) *res.ProductSpecificationsResponse {
if spec == nil {
return nil
}
response := &res.ProductSpecificationsResponse{
ID: spec.ID,
ProductID: spec.ProductID,
Title: spec.Title,
ThumbnailPath: spec.ThumbnailPath,
IsActive: spec.IsActive,
CreatedAt: spec.CreatedAt,
UpdatedAt: spec.UpdatedAt,
}
if spec.ThumbnailPath != nil && *spec.ThumbnailPath != "" {
// Extract filename from path
filename := filepath.Base(*spec.ThumbnailPath)
thumbnailUrl := host + "/product-specifications/viewer/" + filename
2025-11-15 17:43:23 +00:00
response.ThumbnailUrl = &thumbnailUrl
}
return response
}