forked from mirrors/homebox
feat: add lookup by asset ID (#208)
* add asset id redirecting * dev env changes * suggested changes from PR * remove unnecessary proxy from nuxt config * fix formatting * change directory reference * fix API key storage * use /a/{id} as redirect * run generators * remove dependabot Co-authored-by: Bradley Nelson <bradley@nel.family> Co-authored-by: Bradley Nelson <BCNelson@users.noreply.github.com>
This commit is contained in:
parent
c78f10ba5d
commit
07441eec8e
14 changed files with 302 additions and 33 deletions
|
@ -356,6 +356,41 @@ func (e *ItemsRepository) QueryByGroup(ctx context.Context, gid uuid.UUID, q Ite
|
|||
|
||||
}
|
||||
|
||||
|
||||
// QueryByAssetID returns items by asset ID. If the item does not exist, an error is returned.
|
||||
func (e *ItemsRepository) QueryByAssetID(ctx context.Context, gid uuid.UUID, assetID AssetID, page int, pageSize int) (PaginationResult[ItemSummary], error) {
|
||||
qb := e.db.Item.Query().Where(
|
||||
item.HasGroupWith(group.ID(gid)),
|
||||
item.AssetID(int(assetID)),
|
||||
)
|
||||
|
||||
if page != -1 || pageSize != -1 {
|
||||
qb.Offset(calculateOffset(page, pageSize)).
|
||||
Limit(pageSize)
|
||||
} else {
|
||||
page = -1
|
||||
pageSize = -1
|
||||
}
|
||||
|
||||
items, err := mapItemsSummaryErr(
|
||||
qb.Order(ent.Asc(item.FieldName)).
|
||||
WithLabel().
|
||||
WithLocation().
|
||||
All(ctx),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return PaginationResult[ItemSummary]{}, err
|
||||
}
|
||||
|
||||
return PaginationResult[ItemSummary]{
|
||||
Page: page,
|
||||
PageSize: pageSize,
|
||||
Total: len(items),
|
||||
Items: items,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetAll returns all the items in the database with the Labels and Locations eager loaded.
|
||||
func (e *ItemsRepository) GetAll(ctx context.Context, gid uuid.UUID) ([]ItemSummary, error) {
|
||||
return mapItemsSummaryErr(e.db.Item.Query().
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue