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

39 lines
1017 B
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"
)
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{
ID: agent.ID,
Name: agent.Name,
JobTitle: agent.JobTitle,
Phone: agent.Phone,
AgentType: agentType,
ProfilePicturePath: agent.ProfilePicturePath,
IsActive: agent.IsActive,
CreatedAt: agent.CreatedAt,
UpdatedAt: agent.UpdatedAt,
}
if agent.ProfilePicturePath != nil && *agent.ProfilePicturePath != "" {
profilePictureUrl := host + "/sales-agents/profile-picture/viewer/" + *agent.ProfilePicturePath
response.ProfilePictureUrl = &profilePictureUrl
}
return response
}