support parentID search

This commit is contained in:
Hayden 2023-11-15 21:25:23 -06:00
parent 2594d4cdb4
commit 56a27abb70
No known key found for this signature in database
GPG key ID: 17CF79474E257545
2 changed files with 7 additions and 0 deletions

View file

@ -27,6 +27,7 @@ import (
// @Param pageSize query int false "items per page" // @Param pageSize query int false "items per page"
// @Param labels query []string false "label Ids" collectionFormat(multi) // @Param labels query []string false "label Ids" collectionFormat(multi)
// @Param locations query []string false "location 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]{} // @Success 200 {object} repo.PaginationResult[repo.ItemSummary]{}
// @Router /v1/items [GET] // @Router /v1/items [GET]
// @Security Bearer // @Security Bearer
@ -56,6 +57,7 @@ func (ctrl *V1Controller) HandleItemsGetAll() errchain.HandlerFunc {
Search: params.Get("q"), Search: params.Get("q"),
LocationIDs: queryUUIDList(params, "locations"), LocationIDs: queryUUIDList(params, "locations"),
LabelIDs: queryUUIDList(params, "labels"), LabelIDs: queryUUIDList(params, "labels"),
ParentItemIDs: queryUUIDList(params, "parentIds"),
IncludeArchived: queryBool(params.Get("includeArchived")), IncludeArchived: queryBool(params.Get("includeArchived")),
Fields: filterFieldItems(params["fields"]), Fields: filterFieldItems(params["fields"]),
OrderBy: params.Get("orderBy"), OrderBy: params.Get("orderBy"),

View file

@ -36,6 +36,7 @@ type (
AssetID AssetID `json:"assetId"` AssetID AssetID `json:"assetId"`
LocationIDs []uuid.UUID `json:"locationIds"` LocationIDs []uuid.UUID `json:"locationIds"`
LabelIDs []uuid.UUID `json:"labelIds"` LabelIDs []uuid.UUID `json:"labelIds"`
ParentItemIDs []uuid.UUID `json:"parentIds"`
SortBy string `json:"sortBy"` SortBy string `json:"sortBy"`
IncludeArchived bool `json:"includeArchived"` IncludeArchived bool `json:"includeArchived"`
Fields []FieldQuery `json:"fields"` Fields []FieldQuery `json:"fields"`
@ -398,6 +399,10 @@ func (e *ItemsRepository) QueryByGroup(ctx context.Context, gid uuid.UUID, q Ite
andPredicates = append(andPredicates, item.Or(fieldPredicates...)) andPredicates = append(andPredicates, item.Or(fieldPredicates...))
} }
if len(q.ParentItemIDs) > 0 {
andPredicates = append(andPredicates, item.HasParentWith(item.IDIn(q.ParentItemIDs...)))
}
} }
if len(andPredicates) > 0 { if len(andPredicates) > 0 {