35 lines
857 B
Go
35 lines
857 B
Go
package mapper
|
|
|
|
import (
|
|
"jaecoo-be/app/database/entity"
|
|
res "jaecoo-be/app/module/banners/response"
|
|
"path/filepath"
|
|
)
|
|
|
|
func BannersResponseMapper(banner *entity.Banners, host string) *res.BannersResponse {
|
|
if banner == nil {
|
|
return nil
|
|
}
|
|
|
|
response := &res.BannersResponse{
|
|
ID: banner.ID,
|
|
Title: banner.Title,
|
|
Description: banner.Description,
|
|
ThumbnailPath: banner.ThumbnailPath,
|
|
Position: banner.Position,
|
|
Status: banner.Status,
|
|
IsActive: banner.IsActive,
|
|
CreatedAt: banner.CreatedAt,
|
|
UpdatedAt: banner.UpdatedAt,
|
|
}
|
|
|
|
if banner.ThumbnailPath != nil && *banner.ThumbnailPath != "" {
|
|
// Extract filename from path
|
|
filename := filepath.Base(*banner.ThumbnailPath)
|
|
thumbnailUrl := host + "/banners/viewer/" + filename
|
|
response.ThumbnailUrl = &thumbnailUrl
|
|
}
|
|
|
|
return response
|
|
}
|