aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api/v1/org/hook.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/org/hook.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/org/hook.go')
-rw-r--r--routers/api/v1/org/hook.go15
1 files changed, 10 insertions, 5 deletions
diff --git a/routers/api/v1/org/hook.go b/routers/api/v1/org/hook.go
index c7b0bd5b6b..b3faac7b51 100644
--- a/routers/api/v1/org/hook.go
+++ b/routers/api/v1/org/hook.go
@@ -5,6 +5,8 @@
package org
import (
+ "net/http"
+
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
@@ -28,17 +30,18 @@ func ListHooks(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/HookList"
+
org := ctx.Org.Organization
orgHooks, err := models.GetWebhooksByOrgID(org.ID)
if err != nil {
- ctx.Error(500, "GetWebhooksByOrgID", err)
+ ctx.Error(http.StatusInternalServerError, "GetWebhooksByOrgID", err)
return
}
hooks := make([]*api.Hook, len(orgHooks))
for i, hook := range orgHooks {
hooks[i] = convert.ToHook(org.HomeLink(), hook)
}
- ctx.JSON(200, hooks)
+ ctx.JSON(http.StatusOK, hooks)
}
// GetHook get an organization's hook by id
@@ -63,13 +66,14 @@ func GetHook(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/Hook"
+
org := ctx.Org.Organization
hookID := ctx.ParamsInt64(":id")
hook, err := utils.GetOrgHook(ctx, org.ID, hookID)
if err != nil {
return
}
- ctx.JSON(200, convert.ToHook(org.HomeLink(), hook))
+ ctx.JSON(http.StatusOK, convert.ToHook(org.HomeLink(), hook))
}
// CreateHook create a hook for an organization
@@ -159,15 +163,16 @@ func DeleteHook(ctx *context.APIContext) {
// responses:
// "204":
// "$ref": "#/responses/empty"
+
org := ctx.Org.Organization
hookID := ctx.ParamsInt64(":id")
if err := models.DeleteWebhookByOrgID(org.ID, hookID); err != nil {
if models.IsErrWebhookNotExist(err) {
ctx.NotFound()
} else {
- ctx.Error(500, "DeleteWebhookByOrgID", err)
+ ctx.Error(http.StatusInternalServerError, "DeleteWebhookByOrgID", err)
}
return
}
- ctx.Status(204)
+ ctx.Status(http.StatusNoContent)
}