aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2023-12-11 16:56:48 +0800
committerGitHub <noreply@github.com>2023-12-11 16:56:48 +0800
commit537fa6996214ef42348cfe89bab6f2e04380aeac (patch)
tree2b1d7a5b05b5da1c2cd30f400fd3ca648729c6f5 /routers/web
parent0abb5633e34fd14c2d49de0b4c98f7ba7d98a37e (diff)
downloadgitea-537fa6996214ef42348cfe89bab6f2e04380aeac.tar.gz
gitea-537fa6996214ef42348cfe89bab6f2e04380aeac.zip
Second part of refactor `db.Find` (#28194)
Continue of #27798 and move more functions to `db.Find` and `db.Count`.
Diffstat (limited to 'routers/web')
-rw-r--r--routers/web/repo/issue.go15
-rw-r--r--routers/web/repo/milestone.go12
-rw-r--r--routers/web/user/home.go17
3 files changed, 25 insertions, 19 deletions
diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go
index ba8b49774b..14781be822 100644
--- a/routers/web/repo/issue.go
+++ b/routers/web/repo/issue.go
@@ -510,9 +510,8 @@ func Issues(ctx *context.Context) {
func renderMilestones(ctx *context.Context) {
// Get milestones
- milestones, _, err := issues_model.GetMilestones(ctx, issues_model.GetMilestonesOption{
+ milestones, err := db.Find[issues_model.Milestone](ctx, issues_model.FindMilestoneOptions{
RepoID: ctx.Repo.Repository.ID,
- State: api.StateAll,
})
if err != nil {
ctx.ServerError("GetAllRepoMilestones", err)
@@ -534,17 +533,17 @@ func renderMilestones(ctx *context.Context) {
// RetrieveRepoMilestonesAndAssignees find all the milestones and assignees of a repository
func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *repo_model.Repository) {
var err error
- ctx.Data["OpenMilestones"], _, err = issues_model.GetMilestones(ctx, issues_model.GetMilestonesOption{
- RepoID: repo.ID,
- State: api.StateOpen,
+ ctx.Data["OpenMilestones"], err = db.Find[issues_model.Milestone](ctx, issues_model.FindMilestoneOptions{
+ RepoID: repo.ID,
+ IsClosed: util.OptionalBoolFalse,
})
if err != nil {
ctx.ServerError("GetMilestones", err)
return
}
- ctx.Data["ClosedMilestones"], _, err = issues_model.GetMilestones(ctx, issues_model.GetMilestonesOption{
- RepoID: repo.ID,
- State: api.StateClosed,
+ ctx.Data["ClosedMilestones"], err = db.Find[issues_model.Milestone](ctx, issues_model.FindMilestoneOptions{
+ RepoID: repo.ID,
+ IsClosed: util.OptionalBoolTrue,
})
if err != nil {
ctx.ServerError("GetMilestones", err)
diff --git a/routers/web/repo/milestone.go b/routers/web/repo/milestone.go
index 0e6f630747..fbecabb2b1 100644
--- a/routers/web/repo/milestone.go
+++ b/routers/web/repo/milestone.go
@@ -16,7 +16,6 @@ import (
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/markup/markdown"
"code.gitea.io/gitea/modules/setting"
- "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web"
@@ -46,18 +45,13 @@ func Milestones(ctx *context.Context) {
page = 1
}
- state := structs.StateOpen
- if isShowClosed {
- state = structs.StateClosed
- }
-
- miles, total, err := issues_model.GetMilestones(ctx, issues_model.GetMilestonesOption{
+ miles, total, err := db.FindAndCount[issues_model.Milestone](ctx, issues_model.FindMilestoneOptions{
ListOptions: db.ListOptions{
Page: page,
PageSize: setting.UI.IssuePagingNum,
},
RepoID: ctx.Repo.Repository.ID,
- State: state,
+ IsClosed: util.OptionalBoolOf(isShowClosed),
SortType: sortType,
Name: keyword,
})
@@ -80,7 +74,7 @@ func Milestones(ctx *context.Context) {
url.QueryEscape(keyword), url.QueryEscape(sortType))
if ctx.Repo.Repository.IsTimetrackerEnabled(ctx) {
- if err := miles.LoadTotalTrackedTimes(ctx); err != nil {
+ if err := issues_model.MilestoneList(miles).LoadTotalTrackedTimes(ctx); err != nil {
ctx.ServerError("LoadTotalTrackedTimes", err)
return
}
diff --git a/routers/web/user/home.go b/routers/web/user/home.go
index d54e762429..204d4adbd4 100644
--- a/routers/web/user/home.go
+++ b/routers/web/user/home.go
@@ -212,13 +212,26 @@ func Milestones(ctx *context.Context) {
}
}
- counts, err := issues_model.CountMilestonesByRepoCondAndKw(ctx, userRepoCond, keyword, isShowClosed)
+ counts, err := issues_model.CountMilestonesMap(ctx, issues_model.FindMilestoneOptions{
+ RepoCond: userRepoCond,
+ Name: keyword,
+ IsClosed: util.OptionalBoolOf(isShowClosed),
+ })
if err != nil {
ctx.ServerError("CountMilestonesByRepoIDs", err)
return
}
- milestones, err := issues_model.SearchMilestones(ctx, repoCond, page, isShowClosed, sortType, keyword)
+ milestones, err := db.Find[issues_model.Milestone](ctx, issues_model.FindMilestoneOptions{
+ ListOptions: db.ListOptions{
+ Page: page,
+ PageSize: setting.UI.IssuePagingNum,
+ },
+ RepoCond: repoCond,
+ IsClosed: util.OptionalBoolOf(isShowClosed),
+ SortType: sortType,
+ Name: keyword,
+ })
if err != nil {
ctx.ServerError("SearchMilestones", err)
return