diff options
author | Morlinest <Morlinest@users.noreply.github.com> | 2017-09-22 14:53:21 +0200 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2017-09-22 15:53:21 +0300 |
commit | 9a75a5d59bcf9aaff596a7df36ab3aa5b46477a8 (patch) | |
tree | a1a7d87e89387ba3c76313f81fc95d252bbc178a /routers | |
parent | ca68a75b5b8d457f56905ebb7e56d4b7c4566c2e (diff) | |
download | gitea-9a75a5d59bcf9aaff596a7df36ab3aa5b46477a8.tar.gz gitea-9a75a5d59bcf9aaff596a7df36ab3aa5b46477a8.zip |
Use custom type and constants to hold order by options (#2572)
Diffstat (limited to 'routers')
-rw-r--r-- | routers/home.go | 18 | ||||
-rw-r--r-- | routers/user/profile.go | 20 |
2 files changed, 19 insertions, 19 deletions
diff --git a/routers/home.go b/routers/home.go index 16d0720551..381bdd20ae 100644 --- a/routers/home.go +++ b/routers/home.go @@ -86,27 +86,27 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { repos []*models.Repository count int64 err error - orderBy string + orderBy models.SearchOrderBy ) ctx.Data["SortType"] = ctx.Query("sort") switch ctx.Query("sort") { case "oldest": - orderBy = "created_unix ASC" + orderBy = models.SearchOrderByOldest case "recentupdate": - orderBy = "updated_unix DESC" + orderBy = models.SearchOrderByRecentUpdated case "leastupdate": - orderBy = "updated_unix ASC" + orderBy = models.SearchOrderByLeastUpdated case "reversealphabetically": - orderBy = "name DESC" + orderBy = models.SearchOrderByAlphabeticallyReverse case "alphabetically": - orderBy = "name ASC" + orderBy = models.SearchOrderByAlphabetically case "reversesize": - orderBy = "size DESC" + orderBy = models.SearchOrderBySizeReverse case "size": - orderBy = "size ASC" + orderBy = models.SearchOrderBySize default: - orderBy = "created_unix DESC" + orderBy = models.SearchOrderByNewest } keyword := strings.Trim(ctx.Query("q"), " ") diff --git a/routers/user/profile.go b/routers/user/profile.go index 23f5057727..50d0c2397f 100644 --- a/routers/user/profile.go +++ b/routers/user/profile.go @@ -107,26 +107,26 @@ func Profile(ctx *context.Context) { var ( repos []*models.Repository count int64 - orderBy string + orderBy models.SearchOrderBy ) ctx.Data["SortType"] = ctx.Query("sort") switch ctx.Query("sort") { case "newest": - orderBy = "created_unix DESC" + orderBy = models.SearchOrderByNewest case "oldest": - orderBy = "created_unix ASC" + orderBy = models.SearchOrderByOldest case "recentupdate": - orderBy = "updated_unix DESC" + orderBy = models.SearchOrderByRecentUpdated case "leastupdate": - orderBy = "updated_unix ASC" + orderBy = models.SearchOrderByLeastUpdated case "reversealphabetically": - orderBy = "name DESC" + orderBy = models.SearchOrderByAlphabeticallyReverse case "alphabetically": - orderBy = "name ASC" + orderBy = models.SearchOrderByAlphabetically default: ctx.Data["SortType"] = "recentupdate" - orderBy = "updated_unix DESC" + orderBy = models.SearchOrderByNewest } // set default sort value if sort is empty. @@ -149,7 +149,7 @@ func Profile(ctx *context.Context) { case "stars": ctx.Data["PageIsProfileStarList"] = true if len(keyword) == 0 { - repos, err = ctxUser.GetStarredRepos(showPrivate, page, setting.UI.User.RepoPagingNum, orderBy) + repos, err = ctxUser.GetStarredRepos(showPrivate, page, setting.UI.User.RepoPagingNum, orderBy.String()) if err != nil { ctx.Handle(500, "GetStarredRepos", err) return @@ -182,7 +182,7 @@ func Profile(ctx *context.Context) { default: if len(keyword) == 0 { var total int - repos, err = models.GetUserRepositories(ctxUser.ID, showPrivate, page, setting.UI.User.RepoPagingNum, orderBy) + repos, err = models.GetUserRepositories(ctxUser.ID, showPrivate, page, setting.UI.User.RepoPagingNum, orderBy.String()) if err != nil { ctx.Handle(500, "GetRepositories", err) return |