diff options
author | 6543 <6543@obermui.de> | 2019-12-20 18:07:12 +0100 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2019-12-20 19:07:12 +0200 |
commit | 2848c5eb8f7333b6791afd296b12d21751d0516b (patch) | |
tree | 67ff6244026174116edbff1b4c4cdb5934401968 /routers/api/v1/repo/issue_subscription.go | |
parent | 050a8af4243d7f5fff0a2f492b9166f4dfdf0ecf (diff) | |
download | gitea-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_subscription.go')
-rw-r--r-- | routers/api/v1/repo/issue_subscription.go | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/routers/api/v1/repo/issue_subscription.go b/routers/api/v1/repo/issue_subscription.go index 2c5f75f1ec..153b01de61 100644 --- a/routers/api/v1/repo/issue_subscription.go +++ b/routers/api/v1/repo/issue_subscription.go @@ -5,6 +5,8 @@ package repo import ( + "net/http" + "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" ) @@ -46,7 +48,8 @@ func AddIssueSubscription(ctx *context.APIContext) { // "304": // description: User can only subscribe itself if he is no admin // "404": - // description: Issue not found + // "$ref": "#/responses/notFound" + setIssueSubscription(ctx, true) } @@ -87,7 +90,8 @@ func DelIssueSubscription(ctx *context.APIContext) { // "304": // description: User can only subscribe itself if he is no admin // "404": - // description: Issue not found + // "$ref": "#/responses/notFound" + setIssueSubscription(ctx, false) } @@ -97,7 +101,7 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) { if models.IsErrIssueNotExist(err) { ctx.NotFound() } else { - ctx.Error(500, "GetIssueByIndex", err) + ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err) } return @@ -108,7 +112,7 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) { if models.IsErrUserNotExist(err) { ctx.NotFound() } else { - ctx.Error(500, "GetUserByName", err) + ctx.Error(http.StatusInternalServerError, "GetUserByName", err) } return @@ -116,16 +120,16 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) { //only admin and user for itself can change subscription if user.ID != ctx.User.ID && !ctx.User.IsAdmin { - ctx.Error(403, "User", nil) + ctx.Error(http.StatusForbidden, "User", nil) return } if err := models.CreateOrUpdateIssueWatch(user.ID, issue.ID, watch); err != nil { - ctx.Error(500, "CreateOrUpdateIssueWatch", err) + ctx.Error(http.StatusInternalServerError, "CreateOrUpdateIssueWatch", err) return } - ctx.Status(201) + ctx.Status(http.StatusCreated) } // GetIssueSubscribers return subscribers of an issue @@ -158,13 +162,14 @@ func GetIssueSubscribers(ctx *context.APIContext) { // "200": // "$ref": "#/responses/UserList" // "404": - // description: Issue not found + // "$ref": "#/responses/notFound" + issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) if err != nil { if models.IsErrIssueNotExist(err) { ctx.NotFound() } else { - ctx.Error(500, "GetIssueByIndex", err) + ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err) } return @@ -172,15 +177,15 @@ func GetIssueSubscribers(ctx *context.APIContext) { iwl, err := models.GetIssueWatchers(issue.ID) if err != nil { - ctx.Error(500, "GetIssueWatchers", err) + ctx.Error(http.StatusInternalServerError, "GetIssueWatchers", err) return } users, err := iwl.LoadWatchUsers() if err != nil { - ctx.Error(500, "LoadWatchUsers", err) + ctx.Error(http.StatusInternalServerError, "LoadWatchUsers", err) return } - ctx.JSON(200, users.APIFormat()) + ctx.JSON(http.StatusOK, users.APIFormat()) } |