Skip to content

Commit cf0332a

Browse files
committed
cleanup
1 parent 18ac502 commit cf0332a

File tree

6 files changed

+26
-18
lines changed

6 files changed

+26
-18
lines changed

models/issue_reaction.go

+15-5
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,24 @@ func (list ReactionList) GetMoreUserCount() int {
257257
}
258258

259259
// APIFormat returns Raction in api Format
260-
func (list ReactionList) APIFormat() api.CommentReactionList {
261-
result := []*api.CommentReaction{}
260+
func (list ReactionList) APIFormat() []*api.CommentReaction {
261+
var result []*api.CommentReaction
262262
users := make(map[string][]*string)
263263
counts := make(map[string]int64)
264264

265265
for _, r := range list {
266-
users[r.Type] = append(users[r.Type], &r.User.LoginName)
267-
counts[r.Type]++
266+
u := r.User
267+
t := r.Type
268+
if t == "" {
269+
_ = fmt.Errorf("Key is empty!")
270+
continue
271+
}
272+
if u == nil {
273+
_ = fmt.Errorf("Key: '" + t + "', User is Nil!")
274+
continue
275+
}
276+
users[t] = append(users[t], &u.LoginName)
277+
counts[t]++
268278
}
269279

270280
for k, v := range users {
@@ -274,5 +284,5 @@ func (list ReactionList) APIFormat() api.CommentReactionList {
274284
Count: counts[k],
275285
})
276286
}
277-
return api.CommentReactionList{CommentReactions: result}
287+
return result
278288
}

modules/structs/issue_comment.go

-5
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,3 @@ type CommentReaction struct {
4444
Users []*string `json:"users"`
4545
Count int64 `json:"count"`
4646
}
47-
48-
// CommentReactionList is a list of comment reactions
49-
type CommentReactionList struct {
50-
CommentReactions []*CommentReaction `json:"comment_reactions"`
51-
}

routers/api/v1/api.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ func RegisterRoutes(m *macaron.Macaron) {
662662
Patch(mustNotBeArchived, bind(api.EditIssueCommentOption{}), repo.EditIssueComment).
663663
Delete(repo.DeleteIssueComment)
664664
m.Combo("/reactions").
665-
Get(bind(api.CommentReactionList{}), repo.GetCommentReactions).
665+
Get(repo.GetCommentReactions).
666666
Put(reqToken(), bind(api.CommentReaction{}), repo.AddCommentReaction).
667667
Delete(reqToken(), bind(api.CommentReaction{}), repo.DelCommentReaction)
668668
})

routers/api/v1/repo/issue_comment.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ func deleteIssueComment(ctx *context.APIContext) {
395395
}
396396

397397
//GetCommentReactions return all reactions of a specific comment
398-
func GetCommentReactions(ctx *context.APIContext, form api.CommentReactionList) {
398+
func GetCommentReactions(ctx *context.APIContext) {
399399
// swagger:operation GET /repos/{owner}/{repo}/issues/comments/{id}/reactions issue issueGetCommentReactions
400400
// ---
401401
// summary: Return all reactions of a specific comment
@@ -534,12 +534,12 @@ func setCommentReaction(ctx *context.APIContext, form api.CommentReaction, creat
534534
}
535535
return
536536
}
537-
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, comment.IssueID)
537+
issue, err := models.GetIssueByID(comment.IssueID)
538538
if err != nil {
539539
if models.IsErrIssueNotExist(err) {
540540
ctx.NotFound()
541541
} else {
542-
ctx.Error(500, "GetIssueByIndex", err)
542+
ctx.Error(500, "GetIssueByID", err)
543543
}
544544

545545
return

routers/api/v1/swagger/issue.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ type swaggerIssueDeadline struct {
8989
// swagger:response CommentReaction
9090
type swaggerCommentReaction struct {
9191
// in:body
92-
Body api.CommentReactionList `json:"body"`
92+
Body api.CommentReaction `json:"body"`
9393
}
9494

9595
// CommentReactionList
9696
// swagger:response CommentReactionList
97-
type swaggerCommentReactionList struct {
97+
type swaggerResponseCommentReactionList struct {
9898
// in:body
99-
Body api.CommentReactionList `json:"body"`
99+
Body []api.CommentReaction `json:"body"`
100100
}

templates/swagger/v1_json.tmpl

+4-1
Original file line numberDiff line numberDiff line change
@@ -11006,7 +11006,10 @@
1100611006
"CommentReactionList": {
1100711007
"description": "CommentReactionList",
1100811008
"schema": {
11009-
"$ref": "#/definitions/CommentReactionList"
11009+
"type": "array",
11010+
"items": {
11011+
"$ref": "#/definitions/CommentReaction"
11012+
}
1101011013
}
1101111014
},
1101211015
"Commit": {

0 commit comments

Comments
 (0)