Skip to content

A continuation of HomeBox the inventory and organization system built for the Home User

fix: allow zeroing out asset ids (#624)

Haydendf26a3eeb7b4
diff --git a/backend/internal/data/repo/asset_id_type.go b/backend/internal/data/repo/asset_id_type.go
index 678a5101..0a53a4a1 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 d7030637..6ae274b5 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"`