mirror of https://github.com/gogits/gogs.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
129 lines
3.1 KiB
129 lines
3.1 KiB
9 years ago
|
// Copyright 2015 The Gogs Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
package repo
|
||
|
|
||
|
import (
|
||
|
"time"
|
||
|
|
||
|
api "github.com/gogits/go-gogs-client"
|
||
|
|
||
|
"github.com/gogits/gogs/models"
|
||
8 years ago
|
"github.com/gogits/gogs/pkg/context"
|
||
9 years ago
|
)
|
||
|
|
||
8 years ago
|
func ListIssueComments(c *context.APIContext) {
|
||
9 years ago
|
var since time.Time
|
||
8 years ago
|
if len(c.Query("since")) > 0 {
|
||
|
since, _ = time.Parse(time.RFC3339, c.Query("since"))
|
||
9 years ago
|
}
|
||
9 years ago
|
|
||
9 years ago
|
// comments,err:=models.GetCommentsByIssueIDSince(, since)
|
||
8 years ago
|
issue, err := models.GetRawIssueByIndex(c.Repo.Repository.ID, c.ParamsInt64(":index"))
|
||
9 years ago
|
if err != nil {
|
||
8 years ago
|
c.Error(500, "GetRawIssueByIndex", err)
|
||
9 years ago
|
return
|
||
|
}
|
||
|
|
||
9 years ago
|
comments, err := models.GetCommentsByIssueIDSince(issue.ID, since.Unix())
|
||
|
if err != nil {
|
||
8 years ago
|
c.Error(500, "GetCommentsByIssueIDSince", err)
|
||
9 years ago
|
return
|
||
9 years ago
|
}
|
||
|
|
||
9 years ago
|
apiComments := make([]*api.Comment, len(comments))
|
||
|
for i := range comments {
|
||
|
apiComments[i] = comments[i].APIFormat()
|
||
9 years ago
|
}
|
||
8 years ago
|
c.JSON(200, &apiComments)
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
func ListRepoIssueComments(c *context.APIContext) {
|
||
8 years ago
|
var since time.Time
|
||
8 years ago
|
if len(c.Query("since")) > 0 {
|
||
|
since, _ = time.Parse(time.RFC3339, c.Query("since"))
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
comments, err := models.GetCommentsByRepoIDSince(c.Repo.Repository.ID, since.Unix())
|
||
8 years ago
|
if err != nil {
|
||
8 years ago
|
c.Error(500, "GetCommentsByRepoIDSince", err)
|
||
8 years ago
|
return
|
||
|
}
|
||
|
|
||
|
apiComments := make([]*api.Comment, len(comments))
|
||
|
for i := range comments {
|
||
|
apiComments[i] = comments[i].APIFormat()
|
||
|
}
|
||
8 years ago
|
c.JSON(200, &apiComments)
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
func CreateIssueComment(c *context.APIContext, form api.CreateIssueCommentOption) {
|
||
|
issue, err := models.GetIssueByIndex(c.Repo.Repository.ID, c.ParamsInt64(":index"))
|
||
9 years ago
|
if err != nil {
|
||
8 years ago
|
c.Error(500, "GetIssueByIndex", err)
|
||
9 years ago
|
return
|
||
|
}
|
||
|
|
||
8 years ago
|
comment, err := models.CreateIssueComment(c.User, c.Repo.Repository, issue, form.Body, nil)
|
||
9 years ago
|
if err != nil {
|
||
8 years ago
|
c.Error(500, "CreateIssueComment", err)
|
||
9 years ago
|
return
|
||
|
}
|
||
|
|
||
8 years ago
|
c.JSON(201, comment.APIFormat())
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
func EditIssueComment(c *context.APIContext, form api.EditIssueCommentOption) {
|
||
|
comment, err := models.GetCommentByID(c.ParamsInt64(":id"))
|
||
9 years ago
|
if err != nil {
|
||
|
if models.IsErrCommentNotExist(err) {
|
||
8 years ago
|
c.Error(404, "GetCommentByID", err)
|
||
9 years ago
|
} else {
|
||
8 years ago
|
c.Error(500, "GetCommentByID", err)
|
||
9 years ago
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
8 years ago
|
if c.User.ID != comment.PosterID && !c.Repo.IsAdmin() {
|
||
|
c.Status(403)
|
||
9 years ago
|
return
|
||
|
} else if comment.Type != models.COMMENT_TYPE_COMMENT {
|
||
8 years ago
|
c.Status(204)
|
||
9 years ago
|
return
|
||
|
}
|
||
|
|
||
8 years ago
|
oldContent := comment.Content
|
||
9 years ago
|
comment.Content = form.Body
|
||
8 years ago
|
if err := models.UpdateComment(c.User, comment, oldContent); err != nil {
|
||
|
c.Error(500, "UpdateComment", err)
|
||
9 years ago
|
return
|
||
|
}
|
||
8 years ago
|
c.JSON(200, comment.APIFormat())
|
||
9 years ago
|
}
|
||
8 years ago
|
|
||
8 years ago
|
func DeleteIssueComment(c *context.APIContext) {
|
||
|
comment, err := models.GetCommentByID(c.ParamsInt64(":id"))
|
||
8 years ago
|
if err != nil {
|
||
|
if models.IsErrCommentNotExist(err) {
|
||
8 years ago
|
c.Error(404, "GetCommentByID", err)
|
||
8 years ago
|
} else {
|
||
8 years ago
|
c.Error(500, "GetCommentByID", err)
|
||
8 years ago
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
8 years ago
|
if c.User.ID != comment.PosterID && !c.Repo.IsAdmin() {
|
||
|
c.Status(403)
|
||
8 years ago
|
return
|
||
|
} else if comment.Type != models.COMMENT_TYPE_COMMENT {
|
||
8 years ago
|
c.Status(204)
|
||
8 years ago
|
return
|
||
|
}
|
||
|
|
||
8 years ago
|
if err = models.DeleteCommentByID(c.User, comment.ID); err != nil {
|
||
|
c.Error(500, "DeleteCommentByID", err)
|
||
8 years ago
|
return
|
||
|
}
|
||
8 years ago
|
c.Status(204)
|
||
8 years ago
|
}
|