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

41 lines
1.1 KiB
Go
Raw Normal View History

2025-11-15 17:43:23 +00:00
package mapper
import (
"encoding/json"
"jaecoo-be/app/database/entity"
res "jaecoo-be/app/module/sales_agents/response"
2025-11-20 12:18:51 +00:00
"path/filepath"
2025-11-15 17:43:23 +00:00
)
func SalesAgentsResponseMapper(agent *entity.SalesAgents, host string) *res.SalesAgentsResponse {
if agent == nil {
return nil
}
var agentType []string
if agent.AgentType != nil && *agent.AgentType != "" {
json.Unmarshal([]byte(*agent.AgentType), &agentType)
}
response := &res.SalesAgentsResponse{
2025-11-20 12:18:51 +00:00
ID: agent.ID,
Name: agent.Name,
2025-11-15 17:43:23 +00:00
JobTitle: agent.JobTitle,
2025-11-20 12:18:51 +00:00
Phone: agent.Phone,
AgentType: agentType,
2025-11-15 17:43:23 +00:00
ProfilePicturePath: agent.ProfilePicturePath,
2025-11-20 12:18:51 +00:00
IsActive: agent.IsActive,
CreatedAt: agent.CreatedAt,
UpdatedAt: agent.UpdatedAt,
2025-11-15 17:43:23 +00:00
}
if agent.ProfilePicturePath != nil && *agent.ProfilePicturePath != "" {
2025-11-20 12:18:51 +00:00
// Extract filename from path
filename := filepath.Base(*agent.ProfilePicturePath)
profilePictureUrl := host + "/sales-agents/viewer/" + filename
2025-11-15 17:43:23 +00:00
response.ProfilePictureUrl = &profilePictureUrl
}
return response
}