From 63406747df69bba1c5e3ec6775ad2fb5ca92ba8c Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Wed, 19 Oct 2022 21:27:48 -0800 Subject: [PATCH] update return type to be nullable --- backend/app/api/docs/docs.go | 20 +++++++++++++++++++- backend/app/api/docs/swagger.json | 20 +++++++++++++++++++- backend/app/api/docs/swagger.yaml | 15 ++++++++++++++- backend/internal/repo/repo_items.go | 11 ++++++----- 4 files changed, 58 insertions(+), 8 deletions(-) diff --git a/backend/app/api/docs/docs.go b/backend/app/api/docs/docs.go index 2b6483d..29cca73 100644 --- a/backend/app/api/docs/docs.go +++ b/backend/app/api/docs/docs.go @@ -1232,6 +1232,10 @@ const docTemplate = `{ }, "name": { "type": "string" + }, + "parentId": { + "type": "string", + "x-nullable": true } } }, @@ -1270,6 +1274,12 @@ const docTemplate = `{ "$ref": "#/definitions/repo.ItemAttachment" } }, + "children": { + "type": "array", + "items": { + "$ref": "#/definitions/repo.ItemSummary" + } + }, "createdAt": { "type": "string" }, @@ -1277,7 +1287,6 @@ const docTemplate = `{ "type": "string" }, "fields": { - "description": "Future", "type": "array", "items": { "$ref": "#/definitions/repo.ItemField" @@ -1316,6 +1325,11 @@ const docTemplate = `{ "description": "Extras", "type": "string" }, + "parent": { + "x-nullable": true, + "x-omitempty": true, + "$ref": "#/definitions/repo.ItemSummary" + }, "purchaseFrom": { "type": "string" }, @@ -1439,6 +1453,10 @@ const docTemplate = `{ "description": "Extras", "type": "string" }, + "parentId": { + "type": "string", + "x-nullable": true + }, "purchaseFrom": { "type": "string" }, diff --git a/backend/app/api/docs/swagger.json b/backend/app/api/docs/swagger.json index 9aab46d..83f2dd2 100644 --- a/backend/app/api/docs/swagger.json +++ b/backend/app/api/docs/swagger.json @@ -1224,6 +1224,10 @@ }, "name": { "type": "string" + }, + "parentId": { + "type": "string", + "x-nullable": true } } }, @@ -1262,6 +1266,12 @@ "$ref": "#/definitions/repo.ItemAttachment" } }, + "children": { + "type": "array", + "items": { + "$ref": "#/definitions/repo.ItemSummary" + } + }, "createdAt": { "type": "string" }, @@ -1269,7 +1279,6 @@ "type": "string" }, "fields": { - "description": "Future", "type": "array", "items": { "$ref": "#/definitions/repo.ItemField" @@ -1308,6 +1317,11 @@ "description": "Extras", "type": "string" }, + "parent": { + "x-nullable": true, + "x-omitempty": true, + "$ref": "#/definitions/repo.ItemSummary" + }, "purchaseFrom": { "type": "string" }, @@ -1431,6 +1445,10 @@ "description": "Extras", "type": "string" }, + "parentId": { + "type": "string", + "x-nullable": true + }, "purchaseFrom": { "type": "string" }, diff --git a/backend/app/api/docs/swagger.yaml b/backend/app/api/docs/swagger.yaml index 3892c77..11b78ad 100644 --- a/backend/app/api/docs/swagger.yaml +++ b/backend/app/api/docs/swagger.yaml @@ -62,6 +62,9 @@ definitions: type: string name: type: string + parentId: + type: string + x-nullable: true type: object repo.ItemField: properties: @@ -86,12 +89,15 @@ definitions: items: $ref: '#/definitions/repo.ItemAttachment' type: array + children: + items: + $ref: '#/definitions/repo.ItemSummary' + type: array createdAt: type: string description: type: string fields: - description: Future items: $ref: '#/definitions/repo.ItemField' type: array @@ -118,6 +124,10 @@ definitions: notes: description: Extras type: string + parent: + $ref: '#/definitions/repo.ItemSummary' + x-nullable: true + x-omitempty: true purchaseFrom: type: string purchasePrice: @@ -202,6 +212,9 @@ definitions: notes: description: Extras type: string + parentId: + type: string + x-nullable: true purchaseFrom: type: string purchasePrice: diff --git a/backend/internal/repo/repo_items.go b/backend/internal/repo/repo_items.go index acecf73..bf68ce2 100644 --- a/backend/internal/repo/repo_items.go +++ b/backend/internal/repo/repo_items.go @@ -40,7 +40,7 @@ type ( ItemCreate struct { ImportRef string `json:"-"` - ParentID uuid.UUID `json:"parentId"` + ParentID uuid.UUID `json:"parentId" extensions:"x-nullable"` Name string `json:"name"` Description string `json:"description"` @@ -49,7 +49,7 @@ type ( LabelIDs []uuid.UUID `json:"labelIds"` } ItemUpdate struct { - ParentID uuid.UUID `json:"parentId"` + ParentID uuid.UUID `json:"parentId" extensions:"x-nullable"` ID uuid.UUID `json:"id"` Name string `json:"name"` Description string `json:"description"` @@ -102,7 +102,7 @@ type ( } ItemOut struct { - Parent ItemSummary `json:"parent,omitempty"` + Parent *ItemSummary `json:"parent,omitempty" extensions:"x-nullable,x-omitempty"` ItemSummary SerialNumber string `json:"serialNumber"` @@ -202,9 +202,10 @@ func mapItemOut(item *ent.Item) ItemOut { children = mapEach(item.Edges.Children, mapItemSummary) } - var parent ItemSummary + var parent *ItemSummary if item.Edges.Parent != nil { - parent = mapItemSummary(item.Edges.Parent) + v := mapItemSummary(item.Edges.Parent) + parent = &v } return ItemOut{