Skip to content
This repository was archived by the owner on Jun 12, 2024. It is now read-only.

Commit 798d873

Browse files
authored
fix: images in child items (#623)
* support parentID search * fetch images for item children Former-commit-id: afbc6a4
1 parent a26ea3b commit 798d873

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

backend/app/api/handlers/v1/v1_ctrl_items.go

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
// @Param pageSize query int false "items per page"
2828
// @Param labels query []string false "label Ids" collectionFormat(multi)
2929
// @Param locations query []string false "location Ids" collectionFormat(multi)
30+
// @Param parentIds query []string false "parent Ids" collectionFormat(multi)
3031
// @Success 200 {object} repo.PaginationResult[repo.ItemSummary]{}
3132
// @Router /v1/items [GET]
3233
// @Security Bearer
@@ -56,6 +57,7 @@ func (ctrl *V1Controller) HandleItemsGetAll() errchain.HandlerFunc {
5657
Search: params.Get("q"),
5758
LocationIDs: queryUUIDList(params, "locations"),
5859
LabelIDs: queryUUIDList(params, "labels"),
60+
ParentItemIDs: queryUUIDList(params, "parentIds"),
5961
IncludeArchived: queryBool(params.Get("includeArchived")),
6062
Fields: filterFieldItems(params["fields"]),
6163
OrderBy: params.Get("orderBy"),

backend/internal/data/repo/repo_items.go

+5-8
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type (
3636
AssetID AssetID `json:"assetId"`
3737
LocationIDs []uuid.UUID `json:"locationIds"`
3838
LabelIDs []uuid.UUID `json:"labelIds"`
39+
ParentItemIDs []uuid.UUID `json:"parentIds"`
3940
SortBy string `json:"sortBy"`
4041
IncludeArchived bool `json:"includeArchived"`
4142
Fields []FieldQuery `json:"fields"`
@@ -159,7 +160,6 @@ type (
159160

160161
Attachments []ItemAttachment `json:"attachments"`
161162
Fields []ItemField `json:"fields"`
162-
Children []ItemSummary `json:"children"`
163163
}
164164
)
165165

@@ -240,11 +240,6 @@ func mapItemOut(item *ent.Item) ItemOut {
240240
fields = mapFields(item.Edges.Fields)
241241
}
242242

243-
var children []ItemSummary
244-
if item.Edges.Children != nil {
245-
children = mapEach(item.Edges.Children, mapItemSummary)
246-
}
247-
248243
var parent *ItemSummary
249244
if item.Edges.Parent != nil {
250245
v := mapItemSummary(item.Edges.Parent)
@@ -278,7 +273,6 @@ func mapItemOut(item *ent.Item) ItemOut {
278273
Notes: item.Notes,
279274
Attachments: attachments,
280275
Fields: fields,
281-
Children: children,
282276
}
283277
}
284278

@@ -296,7 +290,6 @@ func (e *ItemsRepository) getOne(ctx context.Context, where ...predicate.Item) (
296290
WithLabel().
297291
WithLocation().
298292
WithGroup().
299-
WithChildren().
300293
WithParent().
301294
WithAttachments(func(aq *ent.AttachmentQuery) {
302295
aq.WithDocument()
@@ -398,6 +391,10 @@ func (e *ItemsRepository) QueryByGroup(ctx context.Context, gid uuid.UUID, q Ite
398391

399392
andPredicates = append(andPredicates, item.Or(fieldPredicates...))
400393
}
394+
395+
if len(q.ParentItemIDs) > 0 {
396+
andPredicates = append(andPredicates, item.HasParentWith(item.IDIn(q.ParentItemIDs...)))
397+
}
401398
}
402399

403400
if len(andPredicates) > 0 {

frontend/lib/api/classes/items.ts

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export type ItemsQuery = {
2222
pageSize?: number;
2323
locations?: string[];
2424
labels?: string[];
25+
parentIds?: string[];
2526
q?: string;
2627
fields?: string[];
2728
};

frontend/pages/item/[id]/index.vue

+19-2
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,23 @@
404404
},
405405
];
406406
});
407+
408+
const items = computedAsync(async () => {
409+
if (!item.value) {
410+
return [];
411+
}
412+
413+
const resp = await api.items.getAll({
414+
parentIds: [item.value.id],
415+
});
416+
417+
if (resp.error) {
418+
toast.error("Failed to load items");
419+
return [];
420+
}
421+
422+
return resp.data.items;
423+
});
407424
</script>
408425

409426
<template>
@@ -565,8 +582,8 @@
565582
</div>
566583
</section>
567584

568-
<section v-if="!hasNested && item.children.length > 0" class="my-6">
569-
<ItemViewSelectable :items="item.children" />
585+
<section v-if="items && items.length > 0" class="my-6">
586+
<ItemViewSelectable :items="items" />
570587
</section>
571588
</BaseContainer>
572589
</template>

0 commit comments

Comments
 (0)