diff options
author | 6543 <6543@obermui.de> | 2020-01-13 17:02:24 +0100 |
---|---|---|
committer | Antoine GIRARD <sapk@users.noreply.github.com> | 2020-01-13 17:02:24 +0100 |
commit | 0b3aaa61964faa85b8008b04487388cc362ab436 (patch) | |
tree | cc6a3eda4780b7c8aa2d9e108a8a0ec393fbbb83 /routers | |
parent | b7ffc6a096bdb231d95ecbb5db878e3d8b2b63c9 (diff) | |
download | gitea-0b3aaa61964faa85b8008b04487388cc362ab436.tar.gz gitea-0b3aaa61964faa85b8008b04487388cc362ab436.zip |
[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>
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/repo/issue_comment.go | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/routers/api/v1/repo/issue_comment.go b/routers/api/v1/repo/issue_comment.go index 3085c2e51f..8c97936204 100644 --- a/routers/api/v1/repo/issue_comment.go +++ b/routers/api/v1/repo/issue_comment.go @@ -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 { |