1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2025-08-02 16:35:19 +02:00

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 👍

* use ctx.InternalServerError

* Revert "use numbers and not http.Status___ enum"

This reverts commit b1ff386e2418ed6a7f183e756b13277d701278ef.

* use http.Status* enum everywhere
This commit is contained in:
6543 2019-12-20 18:07:12 +01:00 committed by Lauris BH
parent 050a8af424
commit 2848c5eb8f
52 changed files with 1262 additions and 648 deletions

View file

@ -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())
}