From 8cc0f302919758044dc9ff4dc785c452364dc715 Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Wed, 15 Nov 2023 21:46:47 -0600 Subject: [PATCH] fix: allow zeroing out asset ids (#624) --- backend/internal/data/repo/asset_id_type.go | 5 +++++ backend/internal/data/repo/repo_items.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/backend/internal/data/repo/asset_id_type.go b/backend/internal/data/repo/asset_id_type.go index 678a510..0a53a4a 100644 --- a/backend/internal/data/repo/asset_id_type.go +++ b/backend/internal/data/repo/asset_id_type.go @@ -47,6 +47,11 @@ func (aid AssetID) MarshalJSON() ([]byte, error) { } func (aid *AssetID) UnmarshalJSON(d []byte) error { + if len(d) == 0 || bytes.Equal(d, []byte(`""`)) { + *aid = -1 + return nil + } + d = bytes.Replace(d, []byte(`"`), []byte(``), -1) d = bytes.Replace(d, []byte(`-`), []byte(``), -1) diff --git a/backend/internal/data/repo/repo_items.go b/backend/internal/data/repo/repo_items.go index d703063..6ae274b 100644 --- a/backend/internal/data/repo/repo_items.go +++ b/backend/internal/data/repo/repo_items.go @@ -68,7 +68,7 @@ type ( ItemUpdate struct { ParentID uuid.UUID `json:"parentId" extensions:"x-nullable,x-omitempty"` ID uuid.UUID `json:"id"` - AssetID AssetID `json:"assetId,string"` + AssetID AssetID `json:"assetId"` Name string `json:"name"` Description string `json:"description"` Quantity int `json:"quantity"`