aboutsummaryrefslogtreecommitdiffstats
path: root/models/project/project.go
diff options
context:
space:
mode:
authoryp05327 <576951401@qq.com>2023-07-12 03:47:50 +0900
committerGitHub <noreply@github.com>2023-07-11 20:47:50 +0200
commit44572e924347420d3e11823b93921e01a5529959 (patch)
tree83e8361c259c94318b97a8d1645025d4294a3e42 /models/project/project.go
parent491cc06ffe3491242ad9ff6227423d99e673d0c2 (diff)
downloadgitea-44572e924347420d3e11823b93921e01a5529959.tar.gz
gitea-44572e924347420d3e11823b93921e01a5529959.zip
Fix incorrect oldest sort in project list (#25806)
sort type `oldest` should be `Asc`. Added a test for this.
Diffstat (limited to 'models/project/project.go')
-rw-r--r--models/project/project.go28
1 files changed, 15 insertions, 13 deletions
diff --git a/models/project/project.go b/models/project/project.go
index 44609e60b2..6fa2adf604 100644
--- a/models/project/project.go
+++ b/models/project/project.go
@@ -196,7 +196,7 @@ type SearchOptions struct {
RepoID int64
Page int
IsClosed util.OptionalBool
- SortType string
+ OrderBy db.SearchOrderBy
Type Type
}
@@ -226,26 +226,28 @@ func CountProjects(ctx context.Context, opts SearchOptions) (int64, error) {
return db.GetEngine(ctx).Where(opts.toConds()).Count(new(Project))
}
+func GetSearchOrderByBySortType(sortType string) db.SearchOrderBy {
+ switch sortType {
+ case "oldest":
+ return db.SearchOrderByOldest
+ case "recentupdate":
+ return db.SearchOrderByRecentUpdated
+ case "leastupdate":
+ return db.SearchOrderByLeastUpdated
+ default:
+ return db.SearchOrderByNewest
+ }
+}
+
// FindProjects returns a list of all projects that have been created in the repository
func FindProjects(ctx context.Context, opts SearchOptions) ([]*Project, int64, error) {
- e := db.GetEngine(ctx).Where(opts.toConds())
+ e := db.GetEngine(ctx).Where(opts.toConds()).OrderBy(opts.OrderBy.String())
projects := make([]*Project, 0, setting.UI.IssuePagingNum)
if opts.Page > 0 {
e = e.Limit(setting.UI.IssuePagingNum, (opts.Page-1)*setting.UI.IssuePagingNum)
}
- switch opts.SortType {
- case "oldest":
- e.Desc("created_unix")
- case "recentupdate":
- e.Desc("updated_unix")
- case "leastupdate":
- e.Asc("updated_unix")
- default:
- e.Asc("created_unix")
- }
-
count, err := e.FindAndCount(&projects)
return projects, count, err
}