jaecoo-be/app/module/promotions/mapper/promotions.mapper.go

35 lines
883 B
Go

package mapper
import (
"jaecoo-be/app/database/entity"
res "jaecoo-be/app/module/promotions/response"
"path/filepath"
)
func PromotionsResponseMapper(promotion *entity.Promotions, host string) *res.PromotionsResponse {
if promotion == nil {
return nil
}
response := &res.PromotionsResponse{
ID: promotion.ID,
Title: promotion.Title,
Description: promotion.Description,
ThumbnailPath: promotion.ThumbnailPath,
StatusId: promotion.StatusId,
IsActive: promotion.IsActive,
CreatedAt: promotion.CreatedAt,
UpdatedAt: promotion.UpdatedAt,
}
if promotion.ThumbnailPath != nil && *promotion.ThumbnailPath != "" {
// Extract filename from path
filename := filepath.Base(*promotion.ThumbnailPath)
thumbnailUrl := host + "/promotions/viewer/" + filename
response.ThumbnailUrl = &thumbnailUrl
}
return response
}