summaryrefslogtreecommitdiffstats
path: root/routers/api/v1
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/api/v1
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/api/v1')
-rw-r--r--routers/api/v1/repo/branch.go7
-rw-r--r--routers/api/v1/repo/milestone.go15
2 files changed, 16 insertions, 6 deletions
diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go
index 677105bdb5..36c85c8a57 100644
--- a/routers/api/v1/repo/branch.go
+++ b/routers/api/v1/repo/branch.go
@@ -10,6 +10,7 @@ import (
"net/http"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
git_model "code.gitea.io/gitea/models/git"
"code.gitea.io/gitea/models/organization"
user_model "code.gitea.io/gitea/models/user"
@@ -137,7 +138,7 @@ func DeleteBranch(ctx *context.APIContext) {
}
// check whether branches of this repository has been synced
- totalNumOfBranches, err := git_model.CountBranches(ctx, git_model.FindBranchOptions{
+ totalNumOfBranches, err := db.Count[git_model.Branch](ctx, git_model.FindBranchOptions{
RepoID: ctx.Repo.Repository.ID,
IsDeletedBranch: util.OptionalBoolFalse,
})
@@ -341,7 +342,7 @@ func ListBranches(ctx *context.APIContext) {
IsDeletedBranch: util.OptionalBoolFalse,
}
var err error
- totalNumOfBranches, err = git_model.CountBranches(ctx, branchOpts)
+ totalNumOfBranches, err = db.Count[git_model.Branch](ctx, branchOpts)
if err != nil {
ctx.Error(http.StatusInternalServerError, "CountBranches", err)
return
@@ -360,7 +361,7 @@ func ListBranches(ctx *context.APIContext) {
return
}
- branches, err := git_model.FindBranches(ctx, branchOpts)
+ branches, err := db.Find[git_model.Branch](ctx, branchOpts)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetBranches", err)
return
diff --git a/routers/api/v1/repo/milestone.go b/routers/api/v1/repo/milestone.go
index da470dfa74..9c2ed16d93 100644
--- a/routers/api/v1/repo/milestone.go
+++ b/routers/api/v1/repo/milestone.go
@@ -9,10 +9,12 @@ import (
"strconv"
"time"
+ "code.gitea.io/gitea/models/db"
issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/modules/context"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil"
+ "code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/routers/api/v1/utils"
"code.gitea.io/gitea/services/convert"
@@ -58,14 +60,21 @@ func ListMilestones(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
- milestones, total, err := issues_model.GetMilestones(ctx, issues_model.GetMilestonesOption{
+ state := api.StateType(ctx.FormString("state"))
+ var isClosed util.OptionalBool
+ switch state {
+ case api.StateClosed, api.StateOpen:
+ isClosed = util.OptionalBoolOf(state == api.StateClosed)
+ }
+
+ milestones, total, err := db.FindAndCount[issues_model.Milestone](ctx, issues_model.FindMilestoneOptions{
ListOptions: utils.GetListOptions(ctx),
RepoID: ctx.Repo.Repository.ID,
- State: api.StateType(ctx.FormString("state")),
+ IsClosed: isClosed,
Name: ctx.FormString("name"),
})
if err != nil {
- ctx.Error(http.StatusInternalServerError, "GetMilestones", err)
+ ctx.Error(http.StatusInternalServerError, "db.FindAndCount[issues_model.Milestone]", err)
return
}