From 9b9141cb7c8c3f2d4351bdcfebed90fb3acfd5ac Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Sun, 23 Oct 2022 19:46:26 -0800 Subject: [PATCH] update nil value returns --- backend/internal/repo/repo_items.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/backend/internal/repo/repo_items.go b/backend/internal/repo/repo_items.go index bf68ce2..a47a669 100644 --- a/backend/internal/repo/repo_items.go +++ b/backend/internal/repo/repo_items.go @@ -97,8 +97,8 @@ type ( UpdatedAt time.Time `json:"updatedAt"` // Edges - Location LocationSummary `json:"location"` - Labels []LabelSummary `json:"labels"` + Location *LocationSummary `json:"location,omitempty" extensions:"x-nullable,x-omitempty"` + Labels []LabelSummary `json:"labels"` } ItemOut struct { @@ -139,12 +139,13 @@ var ( ) func mapItemSummary(item *ent.Item) ItemSummary { - var location LocationSummary + var location *LocationSummary if item.Edges.Location != nil { - location = mapLocationSummary(item.Edges.Location) + loc := mapLocationSummary(item.Edges.Location) + location = &loc } - var labels []LabelSummary + labels := make([]LabelSummary, len(item.Edges.Label)) if item.Edges.Label != nil { labels = mapEach(item.Edges.Label, mapLabelSummary) }