From b40615ec9925270ed83c575714017a734cb66a38 Mon Sep 17 00:00:00 2001 From: "n.nakhostin" Date: Sat, 27 Sep 2025 13:24:33 +0330 Subject: [PATCH] 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. --- internal/tender/form.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/tender/form.go b/internal/tender/form.go index 256148d..d1ae145 100644 --- a/internal/tender/form.go +++ b/internal/tender/form.go @@ -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, }