From df8e7c45e32d6a997b4511241df36fb20042ccde Mon Sep 17 00:00:00 2001 From: Wang Yan Date: Fri, 15 Jan 2021 11:22:46 +0800 Subject: [PATCH] fix robot list issue fixes #13985 Add sorting for listing the robot account Signed-off-by: Wang Yan --- src/pkg/robot/dao/dao.go | 3 +++ src/pkg/robot/manager.go | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/pkg/robot/dao/dao.go b/src/pkg/robot/dao/dao.go index 5c351d1fb..a9f548aff 100644 --- a/src/pkg/robot/dao/dao.go +++ b/src/pkg/robot/dao/dao.go @@ -119,6 +119,9 @@ func (d *dao) List(ctx context.Context, query *q.Query) ([]*model.Robot, error) if err != nil { return nil, err } + if query.Sorting != "" { + qs = qs.OrderBy(query.Sorting) + } if _, err = qs.All(&robots); err != nil { return nil, err } diff --git a/src/pkg/robot/manager.go b/src/pkg/robot/manager.go index 2cd95fba1..29125a0fa 100644 --- a/src/pkg/robot/manager.go +++ b/src/pkg/robot/manager.go @@ -81,5 +81,9 @@ func (m *manager) Update(ctx context.Context, r *model.Robot, props ...string) e // List ... func (m *manager) List(ctx context.Context, query *q.Query) ([]*model.Robot, error) { + query = q.MustClone(query) + if query.Sorting == "" { + query.Sorting = "name" + } return m.dao.List(ctx, query) }