diff options
Diffstat (limited to 'routers/api/v1/repo/issue_stopwatch.go')
-rw-r--r-- | routers/api/v1/repo/issue_stopwatch.go | 39 |
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) } |