mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-26 20:26:13 +01:00
add support for query nil
Signed-off-by: wang yan <wangyan@vmware.com>
This commit is contained in:
parent
6bd6fbd4ad
commit
d349c256e8
@ -45,15 +45,15 @@ func GetRobotByID(id int64) (*models.Robot, error) {
|
||||
|
||||
// ListRobots list robots according to the query conditions
|
||||
func ListRobots(query *models.RobotQuery) ([]*models.Robot, error) {
|
||||
qs := getRobotQuerySetter(query)
|
||||
qs := getRobotQuerySetter(query).OrderBy("Name")
|
||||
if query != nil {
|
||||
if query.Size > 0 {
|
||||
qs = qs.Limit(query.Size)
|
||||
if query.Page > 0 {
|
||||
qs = qs.Offset((query.Page - 1) * query.Size)
|
||||
}
|
||||
}
|
||||
qs = qs.OrderBy("Name")
|
||||
|
||||
}
|
||||
robots := []*models.Robot{}
|
||||
_, err := qs.All(&robots)
|
||||
return robots, err
|
||||
@ -61,6 +61,11 @@ func ListRobots(query *models.RobotQuery) ([]*models.Robot, error) {
|
||||
|
||||
func getRobotQuerySetter(query *models.RobotQuery) orm.QuerySeter {
|
||||
qs := GetOrmer().QueryTable(&models.Robot{})
|
||||
|
||||
if query == nil {
|
||||
return qs
|
||||
}
|
||||
|
||||
if len(query.Name) > 0 {
|
||||
if query.FuzzyMatchName {
|
||||
qs = qs.Filter("Name__icontains", query.Name)
|
||||
|
@ -155,3 +155,11 @@ func TestDeleteRobot(t *testing.T) {
|
||||
assert.Nil(t, robot)
|
||||
|
||||
}
|
||||
|
||||
func TestListAllRobot(t *testing.T) {
|
||||
|
||||
robots, err := ListRobots(nil)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, 5, len(robots))
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user