aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api/v1/user/repo.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/repo.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/repo.go')
-rw-r--r--routers/api/v1/user/repo.go17
1 files changed, 11 insertions, 6 deletions
diff --git a/routers/api/v1/user/repo.go b/routers/api/v1/user/repo.go
index 99839b020a..90518f95e5 100644
--- a/routers/api/v1/user/repo.go
+++ b/routers/api/v1/user/repo.go
@@ -5,6 +5,8 @@
package user
import (
+ "net/http"
+
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
api "code.gitea.io/gitea/modules/structs"
@@ -14,7 +16,7 @@ import (
func listUserRepos(ctx *context.APIContext, u *models.User, private bool) {
repos, err := models.GetUserRepositories(u.ID, private, 1, u.NumRepos, "")
if err != nil {
- ctx.Error(500, "GetUserRepositories", err)
+ ctx.Error(http.StatusInternalServerError, "GetUserRepositories", err)
return
}
@@ -22,14 +24,14 @@ func listUserRepos(ctx *context.APIContext, u *models.User, private bool) {
for i := range repos {
access, err := models.AccessLevel(ctx.User, repos[i])
if err != nil {
- ctx.Error(500, "AccessLevel", err)
+ ctx.Error(http.StatusInternalServerError, "AccessLevel", err)
return
}
if ctx.IsSigned && ctx.User.IsAdmin || access >= models.AccessModeRead {
apiRepos = append(apiRepos, repos[i].APIFormat(access))
}
}
- ctx.JSON(200, &apiRepos)
+ ctx.JSON(http.StatusOK, &apiRepos)
}
// ListUserRepos - list the repos owned by the given user.
@@ -48,6 +50,7 @@ func ListUserRepos(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/RepositoryList"
+
user := GetUserByParams(ctx)
if ctx.Written() {
return
@@ -66,14 +69,15 @@ func ListMyRepos(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/RepositoryList"
+
ownRepos, err := models.GetUserRepositories(ctx.User.ID, true, 1, ctx.User.NumRepos, "")
if err != nil {
- ctx.Error(500, "GetUserRepositories", err)
+ ctx.Error(http.StatusInternalServerError, "GetUserRepositories", err)
return
}
accessibleReposMap, err := ctx.User.GetRepositoryAccesses()
if err != nil {
- ctx.Error(500, "GetRepositoryAccesses", err)
+ ctx.Error(http.StatusInternalServerError, "GetRepositoryAccesses", err)
return
}
@@ -86,7 +90,7 @@ func ListMyRepos(ctx *context.APIContext) {
apiRepos[i] = repo.APIFormat(access)
i++
}
- ctx.JSON(200, &apiRepos)
+ ctx.JSON(http.StatusOK, &apiRepos)
}
// ListOrgRepos - list the repositories of an organization.
@@ -105,5 +109,6 @@ func ListOrgRepos(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/RepositoryList"
+
listUserRepos(ctx, ctx.Org.Organization, ctx.IsSigned)
}