summaryrefslogtreecommitdiffstats
path: root/routers/api
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2016-08-26 13:40:53 -0700
committerUnknwon <u@gogs.io>2016-08-26 13:40:53 -0700
commit6b98d58906e4df063a2af59f97bd74c1c4cc1c84 (patch)
tree55ee0ed0cf2ce7984f3e724ba6a8675ece4771c1 /routers/api
parent8dca9f95fab909c52cd34fb401f171d22f0065ae (diff)
downloadgitea-6b98d58906e4df063a2af59f97bd74c1c4cc1c84.tar.gz
gitea-6b98d58906e4df063a2af59f97bd74c1c4cc1c84.zip
#2966 code cleanup
Diffstat (limited to 'routers/api')
-rw-r--r--routers/api/v1/repo/issue.go2
-rw-r--r--routers/api/v1/repo/issue_comment.go80
2 files changed, 21 insertions, 61 deletions
diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go
index b83f7e66b9..fe967ae0a5 100644
--- a/routers/api/v1/repo/issue.go
+++ b/routers/api/v1/repo/issue.go
@@ -25,9 +25,9 @@ func ListIssues(ctx *context.APIContext) {
return
}
+ // FIXME: use IssueList to improve performance.
apiIssues := make([]*api.Issue, len(issues))
for i := range issues {
- // FIXME: use IssueList to improve performance.
if err = issues[i].LoadAttributes(); err != nil {
ctx.Error(500, "LoadAttributes", err)
return
diff --git a/routers/api/v1/repo/issue_comment.go b/routers/api/v1/repo/issue_comment.go
index c3a80f989c..3957600b7b 100644
--- a/routers/api/v1/repo/issue_comment.go
+++ b/routers/api/v1/repo/issue_comment.go
@@ -10,112 +10,72 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/context"
- "github.com/gogits/gogs/modules/log"
)
-const (
- ISO8601Format = "2006-01-02T15:04:05Z"
-)
-
-// ListIssueComments list comments on an issue
func ListIssueComments(ctx *context.APIContext) {
var since time.Time
- var withSince bool
+ if len(ctx.Query("since")) > 0 {
+ since, _ = time.Parse(time.RFC3339, ctx.Query("since"))
+ }
- // we get the issue instead of comments directly
- // because to get comments we need to gets issue first,
- // and there is already comments in the issue
- issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
+ // comments,err:=models.GetCommentsByIssueIDSince(, since)
+ issue, err := models.GetRawIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
- ctx.Error(500, "Comments", err)
+ ctx.Error(500, "GetRawIssueByIndex", err)
return
}
- // parse `since`, by default we don't use `since`
- if len(ctx.Query("since")) > 0 {
- var err error
- since, err = time.Parse(ISO8601Format, ctx.Query("since"))
- if err == nil {
- withSince = true
- }
+ comments, err := models.GetCommentsByIssueIDSince(issue.ID, since.Unix())
+ if err != nil {
+ ctx.Error(500, "GetCommentsByIssueIDSince", err)
+ return
}
- apiComments := []*api.Comment{}
- for _, comment := range issue.Comments {
- if withSince && !comment.Created.After(since) {
- continue
- }
- apiComments = append(apiComments, comment.APIFormat())
+ apiComments := make([]*api.Comment, len(comments))
+ for i := range comments {
+ apiComments[i] = comments[i].APIFormat()
}
-
ctx.JSON(200, &apiComments)
}
-// CreateIssueComment create comment on an issue
func CreateIssueComment(ctx *context.APIContext, form api.CreateIssueCommentOption) {
- // check issue
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
- ctx.Error(500, "Comments", err)
+ ctx.Error(500, "GetIssueByIndex", err)
return
}
- comment := &models.Comment{
- Content: form.Body,
- }
-
- if len(form.Body) == 0 {
- ctx.Handle(400, "CreateIssueComment:empty content", err)
- return
- }
-
- // create comment
- comment, err = models.CreateIssueComment(ctx.User, ctx.Repo.Repository, issue, form.Body, []string{})
+ comment, err := models.CreateIssueComment(ctx.User, ctx.Repo.Repository, issue, form.Body, nil)
if err != nil {
- ctx.Handle(500, "CreateIssueComment", err)
+ ctx.Error(500, "CreateIssueComment", err)
return
}
- log.Trace("Comment created: %d/%d/%d", ctx.Repo.Repository.ID, issue.ID, comment.ID)
-
- // Refetch from database to assign some automatic values
- comment, err = models.GetCommentByID(comment.ID)
- if err != nil {
- log.Info("Failed to refetch comment:%v", err)
- }
ctx.JSON(201, comment.APIFormat())
}
-// EditIssueComment edits an issue comment
func EditIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption) {
comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
if err != nil {
if models.IsErrCommentNotExist(err) {
ctx.Error(404, "GetCommentByID", err)
} else {
- ctx.Handle(500, "GetCommentByID", err)
+ ctx.Error(500, "GetCommentByID", err)
}
return
}
if !ctx.IsSigned || (ctx.User.ID != comment.PosterID && !ctx.Repo.IsAdmin()) {
- ctx.Error(403, "edit comment", err)
+ ctx.Status(403)
return
} else if comment.Type != models.COMMENT_TYPE_COMMENT {
- ctx.Error(204, "edit comment", err)
+ ctx.Status(204)
return
}
comment.Content = form.Body
- if len(comment.Content) == 0 {
- ctx.JSON(200, map[string]interface{}{
- "content": "",
- })
- return
- }
-
if err := models.UpdateComment(comment); err != nil {
- ctx.Handle(500, "UpdateComment", err)
+ ctx.Error(500, "UpdateComment", err)
return
}
ctx.JSON(200, comment.APIFormat())