feat(api): add more sorting to own repository list (#7256)
- Add more sorting options, by leveraging the existing `repo_model.OrderByFlatMap` map, to the `/api/v1/user/repos` endpoint. - Swagger has been updated. - Add (non-exhaustive) integration testing. - Ref: gitnex/GitNex#1266 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7256 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Co-authored-by: Gusted <postmaster@gusted.xyz> Co-committed-by: Gusted <postmaster@gusted.xyz>
This commit is contained in:
parent
9786982c6e
commit
e2aa9adad7
3 changed files with 84 additions and 7 deletions
|
@ -101,8 +101,9 @@ func ListMyRepos(ctx *context.APIContext) {
|
|||
// type: integer
|
||||
// - name: order_by
|
||||
// in: query
|
||||
// description: order the repositories by name (default), id, or size
|
||||
// description: order the repositories
|
||||
// type: string
|
||||
// enum: [name, id, newest, oldest, recentupdate, leastupdate, reversealphabetically, alphabetically, reversesize, size, reversegitsize, gitsize, reverselfssize, lfssize, moststars, feweststars, mostforks, fewestforks]
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/RepositoryList"
|
||||
|
@ -124,14 +125,15 @@ func ListMyRepos(ctx *context.APIContext) {
|
|||
switch orderBy {
|
||||
case "name":
|
||||
opts.OrderBy = "name ASC"
|
||||
case "size":
|
||||
opts.OrderBy = "size DESC"
|
||||
case "id":
|
||||
opts.OrderBy = "id ASC"
|
||||
case "":
|
||||
default:
|
||||
ctx.Error(http.StatusUnprocessableEntity, "", "invalid order_by")
|
||||
return
|
||||
if orderBy, ok := repo_model.OrderByFlatMap[orderBy]; ok {
|
||||
opts.OrderBy = orderBy
|
||||
} else if orderBy != "" {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "", "invalid order_by")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
repos, count, err := repo_model.SearchRepository(ctx, opts)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue