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:
@@ -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,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user