mirror of
https://github.com/goharbor/harbor
synced 2025-04-24 16:03:17 +00:00
fix accessory count issue (#16866)
The count api should ignore the pagination. Signed-off-by: Wang Yan <wangyan@vmware.com>
This commit is contained in:
parent
2852a7606b
commit
ae83f9a027
@ -45,6 +45,12 @@ func New() DAO {
|
||||
type dao struct{}
|
||||
|
||||
func (d *dao) Count(ctx context.Context, query *q.Query) (int64, error) {
|
||||
if query != nil {
|
||||
// ignore the page number and size
|
||||
query = &q.Query{
|
||||
Keywords: query.Keywords,
|
||||
}
|
||||
}
|
||||
qs, err := orm.QuerySetterForCount(ctx, &Accessory{}, query)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
@ -366,19 +366,22 @@ func (a *artifactAPI) ListAccessories(ctx context.Context, params operation.List
|
||||
query.Keywords["SubjectArtifactID"] = artifact.ID
|
||||
|
||||
// list accessories according to the query
|
||||
total, err := a.accMgr.Count(ctx, query)
|
||||
if err != nil {
|
||||
return a.SendError(ctx, err)
|
||||
}
|
||||
accs, err := a.accMgr.List(ctx, query)
|
||||
if err != nil {
|
||||
return a.SendError(ctx, err)
|
||||
}
|
||||
total := len(accs)
|
||||
|
||||
var res []*models.Accessory
|
||||
for _, acc := range accs {
|
||||
res = append(res, model.NewAccessory(acc.GetData()).ToSwagger())
|
||||
}
|
||||
return operation.NewListAccessoriesOK().
|
||||
WithXTotalCount(int64(total)).
|
||||
WithLink(a.Links(ctx, params.HTTPRequest.URL, int64(total), query.PageNumber, query.PageSize).String()).
|
||||
WithXTotalCount(total).
|
||||
WithLink(a.Links(ctx, params.HTTPRequest.URL, total, query.PageNumber, query.PageSize).String()).
|
||||
WithPayload(res)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user