Skip to content

Commit

Permalink
Introduce "sort" in query to provide a general solution for sorting
Browse files Browse the repository at this point in the history
Introduce "sort" in query to provide a general solution for sorting

Signed-off-by: Wenkai Yin <yinw@vmware.com>
  • Loading branch information
ywk253100 committed Mar 11, 2021
1 parent b181d4d commit 506d1ad
Show file tree
Hide file tree
Showing 53 changed files with 685 additions and 525 deletions.
62 changes: 39 additions & 23 deletions api/v2.0/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ paths:
- $ref: '#/parameters/requestId'
- $ref: '#/parameters/page'
- $ref: '#/parameters/pageSize'
- $ref: '#/parameters/sort'
- name: name
in: query
description: The name of project.
Expand Down Expand Up @@ -249,6 +250,7 @@ paths:
- $ref: '#/parameters/requestId'
- $ref: '#/parameters/projectName'
- $ref: '#/parameters/query'
- $ref: '#/parameters/sort'
- $ref: '#/parameters/page'
- $ref: '#/parameters/pageSize'
responses:
Expand Down Expand Up @@ -365,6 +367,7 @@ paths:
- $ref: '#/parameters/projectName'
- $ref: '#/parameters/repositoryName'
- $ref: '#/parameters/query'
- $ref: '#/parameters/sort'
- $ref: '#/parameters/page'
- $ref: '#/parameters/pageSize'
- $ref: '#/parameters/acceptVulnerabilities'
Expand Down Expand Up @@ -639,6 +642,7 @@ paths:
- $ref: '#/parameters/repositoryName'
- $ref: '#/parameters/reference'
- $ref: '#/parameters/query'
- $ref: '#/parameters/sort'
- $ref: '#/parameters/page'
- $ref: '#/parameters/pageSize'
- name: with_signature
Expand Down Expand Up @@ -936,6 +940,7 @@ paths:
parameters:
- $ref: '#/parameters/requestId'
- $ref: '#/parameters/query'
- $ref: '#/parameters/sort'
- $ref: '#/parameters/page'
- $ref: '#/parameters/pageSize'
responses:
Expand Down Expand Up @@ -969,6 +974,7 @@ paths:
- $ref: '#/parameters/projectName'
- $ref: '#/parameters/requestId'
- $ref: '#/parameters/query'
- $ref: '#/parameters/sort'
- $ref: '#/parameters/page'
- $ref: '#/parameters/pageSize'
responses:
Expand Down Expand Up @@ -1056,6 +1062,7 @@ paths:
- $ref: '#/parameters/page'
- $ref: '#/parameters/pageSize'
- $ref: '#/parameters/query'
- $ref: '#/parameters/sort'
responses:
'200':
description: Success
Expand Down Expand Up @@ -1223,6 +1230,7 @@ paths:
- $ref: '#/parameters/page'
- $ref: '#/parameters/pageSize'
- $ref: '#/parameters/query'
- $ref: '#/parameters/sort'
responses:
'200':
description: List preheat policies success
Expand Down Expand Up @@ -1368,6 +1376,7 @@ paths:
- $ref: '#/parameters/page'
- $ref: '#/parameters/pageSize'
- $ref: '#/parameters/query'
- $ref: '#/parameters/sort'
responses:
'200':
description: List executions success
Expand Down Expand Up @@ -1464,6 +1473,7 @@ paths:
- $ref: '#/parameters/page'
- $ref: '#/parameters/pageSize'
- $ref: '#/parameters/query'
- $ref: '#/parameters/sort'
responses:
'200':
description: List tasks success
Expand Down Expand Up @@ -1560,6 +1570,7 @@ paths:
- $ref: '#/parameters/page'
- $ref: '#/parameters/pageSize'
- $ref: '#/parameters/query'
- $ref: '#/parameters/sort'
tags:
- robotv1
operationId: ListRobotV1
Expand Down Expand Up @@ -1717,6 +1728,7 @@ paths:
- $ref: '#/parameters/page'
- $ref: '#/parameters/pageSize'
- $ref: '#/parameters/query'
- $ref: '#/parameters/sort'
responses:
'200':
description: Success
Expand Down Expand Up @@ -1847,6 +1859,7 @@ paths:
parameters:
- $ref: '#/parameters/requestId'
- $ref: '#/parameters/query'
- $ref: '#/parameters/sort'
- $ref: '#/parameters/page'
- $ref: '#/parameters/pageSize'
responses:
Expand Down Expand Up @@ -2126,6 +2139,7 @@ paths:
- replication
operationId: listReplicationExecutions
parameters:
- $ref: '#/parameters/sort'
- $ref: '#/parameters/page'
- $ref: '#/parameters/pageSize'
- name: policy_id
Expand Down Expand Up @@ -2246,6 +2260,7 @@ paths:
- replication
operationId: listReplicationTasks
parameters:
- $ref: '#/parameters/sort'
- $ref: '#/parameters/page'
- $ref: '#/parameters/pageSize'
- name: id
Expand Down Expand Up @@ -2460,6 +2475,7 @@ paths:
operationId: getGCHistory
parameters:
- $ref: '#/parameters/query'
- $ref: '#/parameters/sort'
- $ref: '#/parameters/page'
- $ref: '#/parameters/pageSize'
responses:
Expand Down Expand Up @@ -3240,6 +3256,29 @@ parameters:
in: query
type: string
required: false
sort:
name: sort
description: Sort the resource list in ascending or descending order. e.g. sort by field1 in ascending orderr and field2 in descending order with "sort=field1,-field2"
in: query
type: string
required: false
page:
name: page
in: query
type: integer
format: int64
required: false
description: The page number
default: 1
pageSize:
name: page_size
in: query
type: integer
format: int64
required: false
description: The size of per page
default: 10
maximum: 100
requestId:
name: X-Request-Id
description: An unique ID for the request
Expand Down Expand Up @@ -3305,29 +3344,6 @@ parameters:
description: The name of the tag
required: true
type: string
page:
name: page
in: query
type: integer
format: int64
required: false
description: The page number
default: 1
pageSize:
name: page_size
in: query
type: integer
format: int64
required: false
description: The size of per page
default: 10
maximum: 100
sort:
name: sort
in: query
type: string
required: false
description: The order by fields of the query, the format is '+field1,-field2'.
instanceName:
name: preheat_instance_name
in: path
Expand Down
2 changes: 1 addition & 1 deletion src/common/models/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const (
type Project struct {
ProjectID int64 `orm:"pk;auto;column(project_id)" json:"project_id"`
OwnerID int `orm:"column(owner_id)" json:"owner_id"`
Name string `orm:"column(name)" json:"name"`
Name string `orm:"column(name)" json:"name" sort:"default"`
CreationTime time.Time `orm:"column(creation_time);auto_now_add" json:"creation_time"`
UpdateTime time.Time `orm:"column(update_time);auto_now" json:"update_time"`
Deleted bool `orm:"column(deleted)" json:"deleted"`
Expand Down
2 changes: 1 addition & 1 deletion src/common/models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type RepoRecord struct {
Description string `orm:"column(description)" json:"description"`
PullCount int64 `orm:"column(pull_count)" json:"pull_count"`
StarCount int64 `orm:"column(star_count)" json:"star_count"`
CreationTime time.Time `orm:"column(creation_time);auto_now_add" json:"creation_time"`
CreationTime time.Time `orm:"column(creation_time);auto_now_add" json:"creation_time" sort:"default:desc"`
UpdateTime time.Time `orm:"column(update_time);auto_now" json:"update_time"`
}

Expand Down
2 changes: 1 addition & 1 deletion src/common/models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const UserTable = "harbor_user"
// User holds the details of a user.
type User struct {
UserID int `orm:"pk;auto;column(user_id)" json:"user_id"`
Username string `orm:"column(username)" json:"username"`
Username string `orm:"column(username)" json:"username" sort:"default"`
Email string `orm:"column(email)" json:"email"`
Password string `orm:"column(password)" json:"password"`
PasswordVersion string `orm:"column(password_version)" json:"password_version"`
Expand Down
2 changes: 1 addition & 1 deletion src/core/api/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (t *RegistryAPI) List() {
queryStr = fmt.Sprintf("name=~%s", name)
}
}
query, err := q.Build(queryStr, 0, 0)
query, err := q.Build(queryStr, "", 0, 0)
if err != nil {
t.SendError(err)
return
Expand Down
2 changes: 0 additions & 2 deletions src/core/api/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ func (s *SearchAPI) Get() {
keyword := s.GetString("q")

query := q.New(q.KeyWords{})
query.Sorting = "name"

if keyword != "" {
query.Keywords["name"] = &q.FuzzyMatchValue{Value: keyword}
}
Expand Down
4 changes: 3 additions & 1 deletion src/jobservice/job/impl/gc/garbage_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,9 @@ func (gc *GarbageCollector) removeUntaggedBlobs(ctx job.Context) {
},
PageNumber: 1,
PageSize: int64(ps),
Sorting: "id",
Sorts: []*q.Sort{
q.NewSort("id", false),
},
}
blobs, err := gc.blobMgr.List(ctx.SystemContext(), q)
if err != nil {
Expand Down
Loading

0 comments on commit 506d1ad

Please sign in to comment.