aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api/v1/repo/issue_stopwatch.go
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2019-12-20 18:07:12 +0100
committerLauris BH <lauris@nix.lv>2019-12-20 19:07:12 +0200
commit2848c5eb8f7333b6791afd296b12d21751d0516b (patch)
tree67ff6244026174116edbff1b4c4cdb5934401968 /routers/api/v1/repo/issue_stopwatch.go
parent050a8af4243d7f5fff0a2f492b9166f4dfdf0ecf (diff)
downloadgitea-2848c5eb8f7333b6791afd296b12d21751d0516b.tar.gz
gitea-2848c5eb8f7333b6791afd296b12d21751d0516b.zip
Swagger info corrections (#9441)
* use numbers and not http.Status___ enum * fix test * add many missing swagger responses * code format * Deletion Sould return 204 ... * error handling improvements * if special error type ... then add it to swagger too * one smal nit * invalidTopicsError is []string * valid swagger specification 2.0 - if you add responses swagger can tell you if you do it right :+1: * use ctx.InternalServerError * Revert "use numbers and not http.Status___ enum" This reverts commit b1ff386e2418ed6a7f183e756b13277d701278ef. * use http.Status* enum everywhere
Diffstat (limited to 'routers/api/v1/repo/issue_stopwatch.go')
-rw-r--r--routers/api/v1/repo/issue_stopwatch.go39
1 files changed, 22 insertions, 17 deletions
diff --git a/routers/api/v1/repo/issue_stopwatch.go b/routers/api/v1/repo/issue_stopwatch.go
index 48b2f6498f..3ffdf24404 100644
--- a/routers/api/v1/repo/issue_stopwatch.go
+++ b/routers/api/v1/repo/issue_stopwatch.go
@@ -5,6 +5,8 @@
package repo
import (
+ "net/http"
+
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
)
@@ -41,20 +43,21 @@ func StartIssueStopwatch(ctx *context.APIContext) {
// "403":
// description: Not repo writer, user does not have rights to toggle stopwatch
// "404":
- // description: Issue not found
+ // "$ref": "#/responses/notFound"
// "409":
// description: Cannot start a stopwatch again if it already exists
+
issue, err := prepareIssueStopwatch(ctx, false)
if err != nil {
return
}
if err := models.CreateOrStopIssueStopwatch(ctx.User, issue); err != nil {
- ctx.Error(500, "CreateOrStopIssueStopwatch", err)
+ ctx.Error(http.StatusInternalServerError, "CreateOrStopIssueStopwatch", err)
return
}
- ctx.Status(201)
+ ctx.Status(http.StatusCreated)
}
// StopIssueStopwatch stops a stopwatch for the given issue.
@@ -89,20 +92,21 @@ func StopIssueStopwatch(ctx *context.APIContext) {
// "403":
// description: Not repo writer, user does not have rights to toggle stopwatch
// "404":
- // description: Issue not found
+ // "$ref": "#/responses/notFound"
// "409":
// description: Cannot stop a non existent stopwatch
+
issue, err := prepareIssueStopwatch(ctx, true)
if err != nil {
return
}
if err := models.CreateOrStopIssueStopwatch(ctx.User, issue); err != nil {
- ctx.Error(500, "CreateOrStopIssueStopwatch", err)
+ ctx.Error(http.StatusInternalServerError, "CreateOrStopIssueStopwatch", err)
return
}
- ctx.Status(201)
+ ctx.Status(http.StatusCreated)
}
// DeleteIssueStopwatch delete a specific stopwatch
@@ -137,20 +141,21 @@ func DeleteIssueStopwatch(ctx *context.APIContext) {
// "403":
// description: Not repo writer, user does not have rights to toggle stopwatch
// "404":
- // description: Issue not found
+ // "$ref": "#/responses/notFound"
// "409":
// description: Cannot cancel a non existent stopwatch
+
issue, err := prepareIssueStopwatch(ctx, true)
if err != nil {
return
}
if err := models.CancelStopwatch(ctx.User, issue); err != nil {
- ctx.Error(500, "CancelStopwatch", err)
+ ctx.Error(http.StatusInternalServerError, "CancelStopwatch", err)
return
}
- ctx.Status(204)
+ ctx.Status(http.StatusNoContent)
}
func prepareIssueStopwatch(ctx *context.APIContext, shouldExist bool) (*models.Issue, error) {
@@ -159,27 +164,27 @@ func prepareIssueStopwatch(ctx *context.APIContext, shouldExist bool) (*models.I
if models.IsErrIssueNotExist(err) {
ctx.NotFound()
} else {
- ctx.Error(500, "GetIssueByIndex", err)
+ ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
}
return nil, err
}
if !ctx.Repo.CanWrite(models.UnitTypeIssues) {
- ctx.Status(403)
+ ctx.Status(http.StatusForbidden)
return nil, err
}
if !ctx.Repo.CanUseTimetracker(issue, ctx.User) {
- ctx.Status(403)
+ ctx.Status(http.StatusForbidden)
return nil, err
}
if models.StopwatchExists(ctx.User.ID, issue.ID) != shouldExist {
if shouldExist {
- ctx.Error(409, "StopwatchExists", "cannot stop/cancel a non existent stopwatch")
+ ctx.Error(http.StatusConflict, "StopwatchExists", "cannot stop/cancel a non existent stopwatch")
} else {
- ctx.Error(409, "StopwatchExists", "cannot start a stopwatch again if it already exists")
+ ctx.Error(http.StatusConflict, "StopwatchExists", "cannot start a stopwatch again if it already exists")
}
return nil, err
}
@@ -202,15 +207,15 @@ func GetStopwatches(ctx *context.APIContext) {
sws, err := models.GetUserStopwatches(ctx.User.ID)
if err != nil {
- ctx.Error(500, "GetUserStopwatches", err)
+ ctx.Error(http.StatusInternalServerError, "GetUserStopwatches", err)
return
}
apiSWs, err := sws.APIFormat()
if err != nil {
- ctx.Error(500, "APIFormat", err)
+ ctx.Error(http.StatusInternalServerError, "APIFormat", err)
return
}
- ctx.JSON(200, apiSWs)
+ ctx.JSON(http.StatusOK, apiSWs)
}