Update TenderResponse Structure to Handle BuyerOrganization Safely

- Modified the ToResponse method in the Tender entity to create an OrganizationResponse instance for BuyerOrganization, ensuring safe access to its Name field.
- This change improves the robustness of the response structure by preventing potential nil dereference errors when BuyerOrganization is not set.
This commit is contained in:
n.nakhostin
2025-09-27 13:24:33 +03:30
parent ac7eb0385d
commit b40615ec99
+6 -1
View File
@@ -70,6 +70,11 @@ type OrganizationResponse struct {
// ToTenderResponse converts a Tender entity to TenderResponse
func (t *Tender) ToResponse() *TenderResponse {
org := &OrganizationResponse{}
if t.BuyerOrganization != nil {
org.Name = t.BuyerOrganization.Name
}
response := &TenderResponse{
ID: t.ID.Hex(),
NoticePublicationID: t.NoticePublicationID,
@@ -87,7 +92,7 @@ func (t *Tender) ToResponse() *TenderResponse {
ApplicationDeadline: t.ApplicationDeadline,
CountryCode: t.CountryCode,
SubmissionURL: t.SubmissionURL,
BuyerOrganization: &OrganizationResponse{Name: t.BuyerOrganization.Name},
BuyerOrganization: org,
Status: t.Status,
TenderID: t.TenderID,
}