summaryrefslogtreecommitdiffstats
path: root/routers/api/v1
diff options
context:
space:
mode:
Diffstat (limited to 'routers/api/v1')
-rw-r--r--routers/api/v1/repo/issue_reaction.go50
-rw-r--r--routers/api/v1/swagger/issue.go23
-rw-r--r--routers/api/v1/swagger/options.go3
3 files changed, 39 insertions, 37 deletions
diff --git a/routers/api/v1/repo/issue_reaction.go b/routers/api/v1/repo/issue_reaction.go
index 4b06bb987c..bbc767cc99 100644
--- a/routers/api/v1/repo/issue_reaction.go
+++ b/routers/api/v1/repo/issue_reaction.go
@@ -41,7 +41,7 @@ func GetIssueCommentReactions(ctx *context.APIContext) {
// required: true
// responses:
// "200":
- // "$ref": "#/responses/ReactionResponseList"
+ // "$ref": "#/responses/ReactionList"
// "403":
// "$ref": "#/responses/forbidden"
@@ -71,9 +71,9 @@ func GetIssueCommentReactions(ctx *context.APIContext) {
return
}
- var result []api.ReactionResponse
+ var result []api.Reaction
for _, r := range reactions {
- result = append(result, api.ReactionResponse{
+ result = append(result, api.Reaction{
User: r.User.APIFormat(),
Reaction: r.Type,
Created: r.CreatedUnix.AsTime(),
@@ -114,8 +114,10 @@ func PostIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOpti
// schema:
// "$ref": "#/definitions/EditReactionOption"
// responses:
+ // "200":
+ // "$ref": "#/responses/Reaction"
// "201":
- // "$ref": "#/responses/ReactionResponse"
+ // "$ref": "#/responses/Reaction"
// "403":
// "$ref": "#/responses/forbidden"
@@ -188,19 +190,20 @@ func changeIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOp
if err != nil {
if models.IsErrForbiddenIssueReaction(err) {
ctx.Error(http.StatusForbidden, err.Error(), err)
+ } else if models.IsErrReactionAlreadyExist(err) {
+ ctx.JSON(http.StatusOK, api.Reaction{
+ User: ctx.User.APIFormat(),
+ Reaction: reaction.Type,
+ Created: reaction.CreatedUnix.AsTime(),
+ })
} else {
ctx.Error(http.StatusInternalServerError, "CreateCommentReaction", err)
}
return
}
- _, err = reaction.LoadUser()
- if err != nil {
- ctx.Error(http.StatusInternalServerError, "Reaction.LoadUser()", err)
- return
- }
- ctx.JSON(http.StatusCreated, api.ReactionResponse{
- User: reaction.User.APIFormat(),
+ ctx.JSON(http.StatusCreated, api.Reaction{
+ User: ctx.User.APIFormat(),
Reaction: reaction.Type,
Created: reaction.CreatedUnix.AsTime(),
})
@@ -244,7 +247,7 @@ func GetIssueReactions(ctx *context.APIContext) {
// required: true
// responses:
// "200":
- // "$ref": "#/responses/ReactionResponseList"
+ // "$ref": "#/responses/ReactionList"
// "403":
// "$ref": "#/responses/forbidden"
@@ -274,9 +277,9 @@ func GetIssueReactions(ctx *context.APIContext) {
return
}
- var result []api.ReactionResponse
+ var result []api.Reaction
for _, r := range reactions {
- result = append(result, api.ReactionResponse{
+ result = append(result, api.Reaction{
User: r.User.APIFormat(),
Reaction: r.Type,
Created: r.CreatedUnix.AsTime(),
@@ -317,8 +320,10 @@ func PostIssueReaction(ctx *context.APIContext, form api.EditReactionOption) {
// schema:
// "$ref": "#/definitions/EditReactionOption"
// responses:
+ // "200":
+ // "$ref": "#/responses/Reaction"
// "201":
- // "$ref": "#/responses/ReactionResponse"
+ // "$ref": "#/responses/Reaction"
// "403":
// "$ref": "#/responses/forbidden"
@@ -386,19 +391,20 @@ func changeIssueReaction(ctx *context.APIContext, form api.EditReactionOption, i
if err != nil {
if models.IsErrForbiddenIssueReaction(err) {
ctx.Error(http.StatusForbidden, err.Error(), err)
+ } else if models.IsErrReactionAlreadyExist(err) {
+ ctx.JSON(http.StatusOK, api.Reaction{
+ User: ctx.User.APIFormat(),
+ Reaction: reaction.Type,
+ Created: reaction.CreatedUnix.AsTime(),
+ })
} else {
ctx.Error(http.StatusInternalServerError, "CreateCommentReaction", err)
}
return
}
- _, err = reaction.LoadUser()
- if err != nil {
- ctx.Error(http.StatusInternalServerError, "Reaction.LoadUser()", err)
- return
- }
- ctx.JSON(http.StatusCreated, api.ReactionResponse{
- User: reaction.User.APIFormat(),
+ ctx.JSON(http.StatusCreated, api.Reaction{
+ User: ctx.User.APIFormat(),
Reaction: reaction.Type,
Created: reaction.CreatedUnix.AsTime(),
})
diff --git a/routers/api/v1/swagger/issue.go b/routers/api/v1/swagger/issue.go
index 68c0a9a38d..b12ea0096a 100644
--- a/routers/api/v1/swagger/issue.go
+++ b/routers/api/v1/swagger/issue.go
@@ -99,23 +99,16 @@ type swaggerResponseStopWatchList struct {
Body []api.StopWatch `json:"body"`
}
-// EditReactionOption
-// swagger:response EditReactionOption
-type swaggerEditReactionOption struct {
+// Reaction
+// swagger:response Reaction
+type swaggerReaction struct {
// in:body
- Body api.EditReactionOption `json:"body"`
+ Body api.Reaction `json:"body"`
}
-// ReactionResponse
-// swagger:response ReactionResponse
-type swaggerReactionResponse struct {
+// ReactionList
+// swagger:response ReactionList
+type swaggerReactionList struct {
// in:body
- Body api.ReactionResponse `json:"body"`
-}
-
-// ReactionResponseList
-// swagger:response ReactionResponseList
-type swaggerReactionResponseList struct {
- // in:body
- Body []api.ReactionResponse `json:"body"`
+ Body []api.Reaction `json:"body"`
}
diff --git a/routers/api/v1/swagger/options.go b/routers/api/v1/swagger/options.go
index 74a475e275..83cbb3a74d 100644
--- a/routers/api/v1/swagger/options.go
+++ b/routers/api/v1/swagger/options.go
@@ -123,4 +123,7 @@ type swaggerParameterBodies struct {
// in:body
RepoTopicOptions api.RepoTopicOptions
+
+ // in:body
+ EditReactionOption api.EditReactionOption
}