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:
Wang Yan 2022-05-17 15:02:29 +08:00 committed by GitHub
parent 2852a7606b
commit ae83f9a027
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View File

@ -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

View File

@ -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)
}