Skip to content

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

fix: images in child items (#623)

Hayden798d873f7639
diff --git a/backend/app/api/handlers/v1/v1_ctrl_items.go b/backend/app/api/handlers/v1/v1_ctrl_items.go
index 49905650..55919f82 100644
--- a/backend/app/api/handlers/v1/v1_ctrl_items.go
+++ b/backend/app/api/handlers/v1/v1_ctrl_items.go
@@ -27,6 +27,7 @@ import (
// @Param pageSize query int false "items per page"
// @Param labels query []string false "label Ids" collectionFormat(multi)
// @Param locations query []string false "location Ids" collectionFormat(multi)
+// @Param parentIds query []string false "parent Ids" collectionFormat(multi)
// @Success 200 {object} repo.PaginationResult[repo.ItemSummary]{}
// @Router /v1/items [GET]
// @Security Bearer
@@ -56,6 +57,7 @@ func (ctrl *V1Controller) HandleItemsGetAll() errchain.HandlerFunc {
Search: params.Get("q"),
LocationIDs: queryUUIDList(params, "locations"),
LabelIDs: queryUUIDList(params, "labels"),
+ ParentItemIDs: queryUUIDList(params, "parentIds"),
IncludeArchived: queryBool(params.Get("includeArchived")),
Fields: filterFieldItems(params["fields"]),
OrderBy: params.Get("orderBy"),
diff --git a/backend/internal/data/repo/repo_items.go b/backend/internal/data/repo/repo_items.go
index a2350ab9..d7030637 100644
--- a/backend/internal/data/repo/repo_items.go
+++ b/backend/internal/data/repo/repo_items.go
@@ -36,6 +36,7 @@ type (
AssetID AssetID `json:"assetId"`
LocationIDs []uuid.UUID `json:"locationIds"`
LabelIDs []uuid.UUID `json:"labelIds"`
+ ParentItemIDs []uuid.UUID `json:"parentIds"`
SortBy string `json:"sortBy"`
IncludeArchived bool `json:"includeArchived"`
Fields []FieldQuery `json:"fields"`
@@ -159,7 +160,6 @@ type (
Attachments []ItemAttachment `json:"attachments"`
Fields []ItemField `json:"fields"`
- Children []ItemSummary `json:"children"`
}
)
@@ -240,11 +240,6 @@ func mapItemOut(item *ent.Item) ItemOut {
fields = mapFields(item.Edges.Fields)
}
- var children []ItemSummary
- if item.Edges.Children != nil {
- children = mapEach(item.Edges.Children, mapItemSummary)
- }
-
var parent *ItemSummary
if item.Edges.Parent != nil {
v := mapItemSummary(item.Edges.Parent)
@@ -278,7 +273,6 @@ func mapItemOut(item *ent.Item) ItemOut {
Notes: item.Notes,
Attachments: attachments,
Fields: fields,
- Children: children,
}
}
@@ -296,7 +290,6 @@ func (e *ItemsRepository) getOne(ctx context.Context, where ...predicate.Item) (
WithLabel().
WithLocation().
WithGroup().
- WithChildren().
WithParent().
WithAttachments(func(aq *ent.AttachmentQuery) {
aq.WithDocument()
@@ -398,6 +391,10 @@ func (e *ItemsRepository) QueryByGroup(ctx context.Context, gid uuid.UUID, q Ite
andPredicates = append(andPredicates, item.Or(fieldPredicates...))
}
+
+ if len(q.ParentItemIDs) > 0 {
+ andPredicates = append(andPredicates, item.HasParentWith(item.IDIn(q.ParentItemIDs...)))
+ }
}
if len(andPredicates) > 0 {
diff --git a/frontend/lib/api/classes/items.ts b/frontend/lib/api/classes/items.ts
index 1a49f26d..fc0ac57b 100644
--- a/frontend/lib/api/classes/items.ts
+++ b/frontend/lib/api/classes/items.ts
@@ -22,6 +22,7 @@ export type ItemsQuery = {
pageSize?: number;
locations?: string[];
labels?: string[];
+ parentIds?: string[];
q?: string;
fields?: string[];
};
diff --git a/frontend/pages/item/[id]/index.vue b/frontend/pages/item/[id]/index.vue
index 1dbde532..7855a5fa 100644
--- a/frontend/pages/item/[id]/index.vue
+++ b/frontend/pages/item/[id]/index.vue
@@ -404,6 +404,23 @@
},
];
});
+
+ const items = computedAsync(async () => {
+ if (!item.value) {
+ return [];
+ }
+
+ const resp = await api.items.getAll({
+ parentIds: [item.value.id],
+ });
+
+ if (resp.error) {
+ toast.error("Failed to load items");
+ return [];
+ }
+
+ return resp.data.items;
+ });
</script>
<template>
@@ -565,8 +582,8 @@
</div>
</section>
- <section v-if="!hasNested && item.children.length > 0" class="my-6">
- <ItemViewSelectable :items="item.children" />
+ <section v-if="items && items.length > 0" class="my-6">
+ <ItemViewSelectable :items="items" />
</section>
</BaseContainer>
</template>