From 24a9888cfcf09d3af078076c1bf80d6a036bd4fc Mon Sep 17 00:00:00 2001 From: Akhilesh Pandey <1akhil.pandey@gmail.com> Date: Wed, 31 May 2023 15:34:53 +0530 Subject: [PATCH] feat: Update HTTP status code to 201 when returning from successful create operations --- internal/api/handler/pullreq/comment_create.go | 2 +- internal/api/handler/pullreq/pr_create.go | 2 +- internal/api/handler/repo/create.go | 2 +- internal/api/handler/repo/create_branch.go | 2 +- internal/api/handler/repo/create_path.go | 2 +- internal/api/handler/repo/create_tag.go | 2 +- internal/api/handler/serviceaccount/create.go | 2 +- internal/api/handler/serviceaccount/create_token.go | 2 +- internal/api/handler/space/create.go | 2 +- internal/api/handler/space/create_path.go | 2 +- internal/api/handler/user/create_access_token.go | 2 +- internal/api/handler/users/create.go | 2 +- internal/api/handler/webhook/create.go | 2 +- internal/api/openapi/user.go | 2 +- internal/api/openapi/users.go | 2 +- internal/api/openapi/webhook.go | 2 +- 16 files changed, 16 insertions(+), 16 deletions(-) diff --git a/internal/api/handler/pullreq/comment_create.go b/internal/api/handler/pullreq/comment_create.go index 188e7a4ca..21e99b51e 100644 --- a/internal/api/handler/pullreq/comment_create.go +++ b/internal/api/handler/pullreq/comment_create.go @@ -44,6 +44,6 @@ func HandleCommentCreate(pullreqCtrl *pullreq.Controller) http.HandlerFunc { return } - render.JSON(w, http.StatusOK, comment) + render.JSON(w, http.StatusCreated, comment) } } diff --git a/internal/api/handler/pullreq/pr_create.go b/internal/api/handler/pullreq/pr_create.go index a1ed8598a..3e8f21e64 100644 --- a/internal/api/handler/pullreq/pr_create.go +++ b/internal/api/handler/pullreq/pr_create.go @@ -38,6 +38,6 @@ func HandleCreate(pullreqCtrl *pullreq.Controller) http.HandlerFunc { return } - render.JSON(w, http.StatusOK, pr) + render.JSON(w, http.StatusCreated, pr) } } diff --git a/internal/api/handler/repo/create.go b/internal/api/handler/repo/create.go index 5aef741c9..867dcf6d1 100644 --- a/internal/api/handler/repo/create.go +++ b/internal/api/handler/repo/create.go @@ -32,6 +32,6 @@ func HandleCreate(repoCtrl *repo.Controller) http.HandlerFunc { return } - render.JSON(w, http.StatusOK, repo) + render.JSON(w, http.StatusCreated, repo) } } diff --git a/internal/api/handler/repo/create_branch.go b/internal/api/handler/repo/create_branch.go index 7f3558597..680f50098 100644 --- a/internal/api/handler/repo/create_branch.go +++ b/internal/api/handler/repo/create_branch.go @@ -39,6 +39,6 @@ func HandleCreateBranch(repoCtrl *repo.Controller) http.HandlerFunc { return } - render.JSON(w, http.StatusOK, branch) + render.JSON(w, http.StatusCreated, branch) } } diff --git a/internal/api/handler/repo/create_path.go b/internal/api/handler/repo/create_path.go index 6bb261801..d774d8563 100644 --- a/internal/api/handler/repo/create_path.go +++ b/internal/api/handler/repo/create_path.go @@ -39,6 +39,6 @@ func HandleCreatePath(repoCtrl *repo.Controller) http.HandlerFunc { return } - render.JSON(w, http.StatusOK, path) + render.JSON(w, http.StatusCreated, path) } } diff --git a/internal/api/handler/repo/create_tag.go b/internal/api/handler/repo/create_tag.go index 378427e88..3cfc57764 100644 --- a/internal/api/handler/repo/create_tag.go +++ b/internal/api/handler/repo/create_tag.go @@ -36,6 +36,6 @@ func HandleCreateCommitTag(repoCtrl *repo.Controller) http.HandlerFunc { return } - render.JSON(w, http.StatusOK, tag) + render.JSON(w, http.StatusCreated, tag) } } diff --git a/internal/api/handler/serviceaccount/create.go b/internal/api/handler/serviceaccount/create.go index 4cb1098d3..7384eabce 100644 --- a/internal/api/handler/serviceaccount/create.go +++ b/internal/api/handler/serviceaccount/create.go @@ -34,6 +34,6 @@ func HandleCreate(saCtrl *serviceaccount.Controller) http.HandlerFunc { return } - render.JSON(w, http.StatusOK, sa) + render.JSON(w, http.StatusCreated, sa) } } diff --git a/internal/api/handler/serviceaccount/create_token.go b/internal/api/handler/serviceaccount/create_token.go index 7565a3b82..8e8781243 100644 --- a/internal/api/handler/serviceaccount/create_token.go +++ b/internal/api/handler/serviceaccount/create_token.go @@ -38,6 +38,6 @@ func HandleCreateToken(saCrl *serviceaccount.Controller) http.HandlerFunc { return } - render.JSON(w, http.StatusOK, tokenResponse) + render.JSON(w, http.StatusCreated, tokenResponse) } } diff --git a/internal/api/handler/space/create.go b/internal/api/handler/space/create.go index cbe53e069..a78ca958d 100644 --- a/internal/api/handler/space/create.go +++ b/internal/api/handler/space/create.go @@ -32,6 +32,6 @@ func HandleCreate(spaceCtrl *space.Controller) http.HandlerFunc { return } - render.JSON(w, http.StatusOK, space) + render.JSON(w, http.StatusCreated, space) } } diff --git a/internal/api/handler/space/create_path.go b/internal/api/handler/space/create_path.go index 74c3580ff..799e5e2d1 100644 --- a/internal/api/handler/space/create_path.go +++ b/internal/api/handler/space/create_path.go @@ -37,6 +37,6 @@ func HandleCreatePath(spaceCtrl *space.Controller) http.HandlerFunc { return } - render.JSON(w, http.StatusOK, path) + render.JSON(w, http.StatusCreated, path) } } diff --git a/internal/api/handler/user/create_access_token.go b/internal/api/handler/user/create_access_token.go index 94238584e..4c8281b75 100644 --- a/internal/api/handler/user/create_access_token.go +++ b/internal/api/handler/user/create_access_token.go @@ -34,6 +34,6 @@ func HandleCreateAccessToken(userCtrl *user.Controller) http.HandlerFunc { return } - render.JSON(w, http.StatusOK, tokenResponse) + render.JSON(w, http.StatusCreated, tokenResponse) } } diff --git a/internal/api/handler/users/create.go b/internal/api/handler/users/create.go index 739e77215..a28e2e0a3 100644 --- a/internal/api/handler/users/create.go +++ b/internal/api/handler/users/create.go @@ -33,6 +33,6 @@ func HandleCreate(userCtrl *user.Controller) http.HandlerFunc { return } - render.JSON(w, http.StatusOK, usr) + render.JSON(w, http.StatusCreated, usr) } } diff --git a/internal/api/handler/webhook/create.go b/internal/api/handler/webhook/create.go index ccd948f5a..e72178a79 100644 --- a/internal/api/handler/webhook/create.go +++ b/internal/api/handler/webhook/create.go @@ -38,6 +38,6 @@ func HandleCreate(webhookCtrl *webhook.Controller) http.HandlerFunc { return } - render.JSON(w, http.StatusOK, hook) + render.JSON(w, http.StatusCreated, hook) } } diff --git a/internal/api/openapi/user.go b/internal/api/openapi/user.go index b90f72bd7..e5cfaae7f 100644 --- a/internal/api/openapi/user.go +++ b/internal/api/openapi/user.go @@ -37,7 +37,7 @@ func buildUser(reflector *openapi3.Reflector) { opToken.WithTags("user") opToken.WithMapOfAnything(map[string]interface{}{"operationId": "createToken"}) _ = reflector.SetRequest(&opToken, new(types.TokenResponse), http.MethodPost) - _ = reflector.SetJSONResponse(&opToken, new(types.User), http.StatusOK) + _ = reflector.SetJSONResponse(&opToken, new(types.User), http.StatusCreated) _ = reflector.SetJSONResponse(&opToken, new(usererror.Error), http.StatusInternalServerError) _ = reflector.Spec.AddOperation(http.MethodPost, "/user/token", opToken) } diff --git a/internal/api/openapi/users.go b/internal/api/openapi/users.go index 7a46daa93..47c164c18 100644 --- a/internal/api/openapi/users.go +++ b/internal/api/openapi/users.go @@ -68,7 +68,7 @@ func buildAdmin(reflector *openapi3.Reflector) { opCreate.WithTags("admin") opCreate.WithMapOfAnything(map[string]interface{}{"operationId": "adminCreateUser"}) _ = reflector.SetRequest(&opCreate, new(adminUsersCreateRequest), http.MethodPost) - _ = reflector.SetJSONResponse(&opCreate, new(types.User), http.StatusOK) + _ = reflector.SetJSONResponse(&opCreate, new(types.User), http.StatusCreated) _ = reflector.SetJSONResponse(&opCreate, new(usererror.Error), http.StatusBadRequest) _ = reflector.SetJSONResponse(&opCreate, new(usererror.Error), http.StatusInternalServerError) _ = reflector.SetJSONResponse(&opCreate, new(usererror.Error), http.StatusNotFound) diff --git a/internal/api/openapi/webhook.go b/internal/api/openapi/webhook.go index 0ac1f2cae..d1324eb00 100644 --- a/internal/api/openapi/webhook.go +++ b/internal/api/openapi/webhook.go @@ -90,7 +90,7 @@ func webhookOperations(reflector *openapi3.Reflector) { createWebhook.WithTags("webhook") createWebhook.WithMapOfAnything(map[string]interface{}{"operationId": "createWebhook"}) _ = reflector.SetRequest(&createWebhook, new(createWebhookRequest), http.MethodPost) - _ = reflector.SetJSONResponse(&createWebhook, new(webhookType), http.StatusOK) + _ = reflector.SetJSONResponse(&createWebhook, new(webhookType), http.StatusCreated) _ = reflector.SetJSONResponse(&createWebhook, new(usererror.Error), http.StatusBadRequest) _ = reflector.SetJSONResponse(&createWebhook, new(usererror.Error), http.StatusInternalServerError) _ = reflector.SetJSONResponse(&createWebhook, new(usererror.Error), http.StatusUnauthorized)