[API] Add "before" query to ListIssueComments and ListRepoIssue… (#9685)

* add "before" query to ListIssueComments and ListRepoIssueComments

* Add TEST

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Antoine GIRARD <sapk@users.noreply.github.com>
This commit is contained in:
6543 2020-01-13 17:02:24 +01:00 committed by Antoine GIRARD
parent b7ffc6a096
commit 0b3aaa6196
5 changed files with 73 additions and 14 deletions

View file

@ -7,11 +7,11 @@ package repo
import (
"errors"
"net/http"
"time"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/routers/api/v1/utils"
comment_service "code.gitea.io/gitea/services/comments"
)
@ -43,16 +43,21 @@ func ListIssueComments(ctx *context.APIContext) {
// in: query
// description: if provided, only comments updated since the specified time are returned.
// type: string
// format: date-time
// - name: before
// in: query
// description: if provided, only comments updated before the provided time are returned.
// type: string
// format: date-time
// responses:
// "200":
// "$ref": "#/responses/CommentList"
var since time.Time
if len(ctx.Query("since")) > 0 {
since, _ = time.Parse(time.RFC3339, ctx.Query("since"))
before, since, err := utils.GetQueryBeforeSince(ctx)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetQueryBeforeSince", err)
return
}
// comments,err:=models.GetCommentsByIssueIDSince(, since)
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetRawIssueByIndex", err)
@ -62,7 +67,8 @@ func ListIssueComments(ctx *context.APIContext) {
comments, err := models.FindComments(models.FindCommentsOptions{
IssueID: issue.ID,
Since: since.Unix(),
Since: since,
Before: before,
Type: models.CommentTypeComment,
})
if err != nil {
@ -105,18 +111,26 @@ func ListRepoIssueComments(ctx *context.APIContext) {
// in: query
// description: if provided, only comments updated since the provided time are returned.
// type: string
// format: date-time
// - name: before
// in: query
// description: if provided, only comments updated before the provided time are returned.
// type: string
// format: date-time
// responses:
// "200":
// "$ref": "#/responses/CommentList"
var since time.Time
if len(ctx.Query("since")) > 0 {
since, _ = time.Parse(time.RFC3339, ctx.Query("since"))
before, since, err := utils.GetQueryBeforeSince(ctx)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetQueryBeforeSince", err)
return
}
comments, err := models.FindComments(models.FindCommentsOptions{
RepoID: ctx.Repo.Repository.ID,
Since: since.Unix(),
Since: since,
Before: before,
Type: models.CommentTypeComment,
})
if err != nil {