summaryrefslogtreecommitdiffstats
path: root/routers/api/v1/user/email.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/user/email.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/user/email.go')
-rw-r--r--routers/api/v1/user/email.go25
1 files changed, 16 insertions, 9 deletions
diff --git a/routers/api/v1/user/email.go b/routers/api/v1/user/email.go
index 8c0eb889ed..07fcde625e 100644
--- a/routers/api/v1/user/email.go
+++ b/routers/api/v1/user/email.go
@@ -5,6 +5,8 @@
package user
import (
+ "net/http"
+
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
@@ -23,16 +25,17 @@ func ListEmails(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/EmailList"
+
emails, err := models.GetEmailAddresses(ctx.User.ID)
if err != nil {
- ctx.Error(500, "GetEmailAddresses", err)
+ ctx.Error(http.StatusInternalServerError, "GetEmailAddresses", err)
return
}
apiEmails := make([]*api.Email, len(emails))
for i := range emails {
apiEmails[i] = convert.ToEmail(emails[i])
}
- ctx.JSON(200, &apiEmails)
+ ctx.JSON(http.StatusOK, &apiEmails)
}
// AddEmail add an email address
@@ -55,8 +58,11 @@ func AddEmail(ctx *context.APIContext, form api.CreateEmailOption) {
// responses:
// '201':
// "$ref": "#/responses/EmailList"
+ // "422":
+ // "$ref": "#/responses/validationError"
+
if len(form.Emails) == 0 {
- ctx.Status(422)
+ ctx.Error(http.StatusUnprocessableEntity, "", "Email list empty")
return
}
@@ -71,9 +77,9 @@ func AddEmail(ctx *context.APIContext, form api.CreateEmailOption) {
if err := models.AddEmailAddresses(emails); err != nil {
if models.IsErrEmailAlreadyUsed(err) {
- ctx.Error(422, "", "Email address has been used: "+err.(models.ErrEmailAlreadyUsed).Email)
+ ctx.Error(http.StatusUnprocessableEntity, "", "Email address has been used: "+err.(models.ErrEmailAlreadyUsed).Email)
} else {
- ctx.Error(500, "AddEmailAddresses", err)
+ ctx.Error(http.StatusInternalServerError, "AddEmailAddresses", err)
}
return
}
@@ -82,7 +88,7 @@ func AddEmail(ctx *context.APIContext, form api.CreateEmailOption) {
for i := range emails {
apiEmails[i] = convert.ToEmail(emails[i])
}
- ctx.JSON(201, &apiEmails)
+ ctx.JSON(http.StatusCreated, &apiEmails)
}
// DeleteEmail delete email
@@ -100,8 +106,9 @@ func DeleteEmail(ctx *context.APIContext, form api.DeleteEmailOption) {
// responses:
// "204":
// "$ref": "#/responses/empty"
+
if len(form.Emails) == 0 {
- ctx.Status(204)
+ ctx.Status(http.StatusNoContent)
return
}
@@ -114,8 +121,8 @@ func DeleteEmail(ctx *context.APIContext, form api.DeleteEmailOption) {
}
if err := models.DeleteEmailAddresses(emails); err != nil {
- ctx.Error(500, "DeleteEmailAddresses", err)
+ ctx.Error(http.StatusInternalServerError, "DeleteEmailAddresses", err)
return
}
- ctx.Status(204)
+ ctx.Status(http.StatusNoContent)
}