Skip to content

Commit a4b7914

Browse files
committed
first draft of setCommentReaction
1 parent ad78480 commit a4b7914

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

routers/api/v1/repo/issue_comment.go

+46
Original file line numberDiff line numberDiff line change
@@ -545,5 +545,51 @@ func DelCommentReaction(ctx *context.APIContext, form api.CommentReaction) {
545545
}
546546

547547
func setCommentReaction(ctx *context.APIContext, form api.CommentReaction, create bool) {
548+
comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
549+
if err != nil {
550+
if models.IsErrCommentNotExist(err) {
551+
ctx.NotFound(err)
552+
} else {
553+
ctx.Error(500, "GetCommentByID", err)
554+
}
555+
return
556+
}
557+
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, comment.IssueID)
558+
if err != nil {
559+
if models.IsErrIssueNotExist(err) {
560+
ctx.NotFound()
561+
} else {
562+
ctx.Error(500, "GetIssueByIndex", err)
563+
}
564+
565+
return
566+
}
567+
568+
for _, u := range form.Users {
569+
user, err := models.GetUserByName(*u)
570+
if err != nil {
571+
ctx.Error(500, "GetUserByName", err)
572+
}
573+
574+
if ctx.User.ID != user.ID && !ctx.Repo.IsAdmin() {
575+
ctx.Status(403)
576+
return
577+
}
578+
579+
if create {
580+
// Create Reaction
581+
_, err = models.CreateCommentReaction(user,issue,comment,form.Reaction)
582+
if err != nil {
583+
ctx.Error(500, "CreateCommentReaction", err)
584+
}
585+
} else {
586+
// Delete Reaction
587+
err = models.DeleteCommentReaction(user,issue,comment,form.Reaction)
588+
if err != nil {
589+
ctx.Error(500, "DeleteCommentReaction", err)
590+
}
591+
}
592+
}
548593

594+
ctx.Status(201)
549595
}

0 commit comments

Comments
 (0)