diff options
author | 6543 <6543@obermui.de> | 2020-05-12 23:54:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-12 22:54:35 +0100 |
commit | 7257c39ddfe9d9d424192e6bd307a70ed544f5be (patch) | |
tree | 67e2fb0861e0b5fe610e424c8b3906db438c6335 /routers | |
parent | ba40263fdda53446c7cae6e41885ebdee8bb7b52 (diff) | |
download | gitea-7257c39ddfe9d9d424192e6bd307a70ed544f5be.tar.gz gitea-7257c39ddfe9d9d424192e6bd307a70ed544f5be.zip |
Refactor Milestone related (#11225)
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/repo/milestone.go | 9 | ||||
-rw-r--r-- | routers/repo/milestone.go | 12 | ||||
-rw-r--r-- | routers/user/home.go | 6 |
3 files changed, 15 insertions, 12 deletions
diff --git a/routers/api/v1/repo/milestone.go b/routers/api/v1/repo/milestone.go index 80d30e2c02..1bfd54df88 100644 --- a/routers/api/v1/repo/milestone.go +++ b/routers/api/v1/repo/milestone.go @@ -11,6 +11,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/convert" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/routers/api/v1/utils" @@ -58,7 +59,7 @@ func ListMilestones(ctx *context.APIContext) { apiMilestones := make([]*api.Milestone, len(milestones)) for i := range milestones { - apiMilestones[i] = milestones[i].APIFormat() + apiMilestones[i] = convert.ToAPIMilestone(milestones[i]) } ctx.JSON(http.StatusOK, &apiMilestones) } @@ -100,7 +101,7 @@ func GetMilestone(ctx *context.APIContext) { } return } - ctx.JSON(http.StatusOK, milestone.APIFormat()) + ctx.JSON(http.StatusOK, convert.ToAPIMilestone(milestone)) } // CreateMilestone create a milestone for a repository @@ -147,7 +148,7 @@ func CreateMilestone(ctx *context.APIContext, form api.CreateMilestoneOption) { ctx.Error(http.StatusInternalServerError, "NewMilestone", err) return } - ctx.JSON(http.StatusCreated, milestone.APIFormat()) + ctx.JSON(http.StatusCreated, convert.ToAPIMilestone(milestone)) } // EditMilestone modify a milestone for a repository @@ -213,7 +214,7 @@ func EditMilestone(ctx *context.APIContext, form api.EditMilestoneOption) { ctx.ServerError("UpdateMilestone", err) return } - ctx.JSON(http.StatusOK, milestone.APIFormat()) + ctx.JSON(http.StatusOK, convert.ToAPIMilestone(milestone)) } // DeleteMilestone delete a milestone for a repository diff --git a/routers/repo/milestone.go b/routers/repo/milestone.go index 5fbf929f35..e30e6371f0 100644 --- a/routers/repo/milestone.go +++ b/routers/repo/milestone.go @@ -15,6 +15,8 @@ import ( "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/util" + + "xorm.io/builder" ) const ( @@ -30,13 +32,13 @@ func Milestones(ctx *context.Context) { ctx.Data["PageIsMilestones"] = true isShowClosed := ctx.Query("state") == "closed" - openCount, closedCount, err := models.MilestoneStats(ctx.Repo.Repository.ID) + stats, err := models.GetMilestonesStatsByRepoCond(builder.And(builder.Eq{"id": ctx.Repo.Repository.ID})) if err != nil { ctx.ServerError("MilestoneStats", err) return } - ctx.Data["OpenCount"] = openCount - ctx.Data["ClosedCount"] = closedCount + ctx.Data["OpenCount"] = stats.OpenCount + ctx.Data["ClosedCount"] = stats.ClosedCount sortType := ctx.Query("sort") page := ctx.QueryInt("page") @@ -46,9 +48,9 @@ func Milestones(ctx *context.Context) { var total int if !isShowClosed { - total = int(openCount) + total = int(stats.OpenCount) } else { - total = int(closedCount) + total = int(stats.ClosedCount) } miles, err := models.GetMilestones(ctx.Repo.Repository.ID, page, isShowClosed, sortType) diff --git a/routers/user/home.go b/routers/user/home.go index 816968562f..199694f236 100644 --- a/routers/user/home.go +++ b/routers/user/home.go @@ -224,7 +224,7 @@ func Milestones(ctx *context.Context) { } } - counts, err := models.CountMilestones(userRepoCond, isShowClosed) + counts, err := models.CountMilestonesByRepoCond(userRepoCond, isShowClosed) if err != nil { ctx.ServerError("CountMilestonesByRepoIDs", err) return @@ -267,7 +267,7 @@ func Milestones(ctx *context.Context) { i++ } - milestoneStats, err := models.GetMilestonesStats(repoCond) + milestoneStats, err := models.GetMilestonesStatsByRepoCond(repoCond) if err != nil { ctx.ServerError("GetMilestoneStats", err) return @@ -277,7 +277,7 @@ func Milestones(ctx *context.Context) { if len(repoIDs) == 0 { totalMilestoneStats = milestoneStats } else { - totalMilestoneStats, err = models.GetMilestonesStats(userRepoCond) + totalMilestoneStats, err = models.GetMilestonesStatsByRepoCond(userRepoCond) if err != nil { ctx.ServerError("GetMilestoneStats", err) return |