summaryrefslogtreecommitdiffstats
path: root/routers/api/v1/user/watch.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/watch.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/watch.go')
-rw-r--r--routers/api/v1/user/watch.go25
1 files changed, 16 insertions, 9 deletions
diff --git a/routers/api/v1/user/watch.go b/routers/api/v1/user/watch.go
index 87739b15fb..ec8543dcf0 100644
--- a/routers/api/v1/user/watch.go
+++ b/routers/api/v1/user/watch.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/setting"
@@ -46,13 +48,14 @@ func GetWatchedRepos(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/RepositoryList"
+
user := GetUserByParams(ctx)
private := user.ID == ctx.User.ID
repos, err := getWatchedRepos(user, private)
if err != nil {
- ctx.Error(500, "getWatchedRepos", err)
+ ctx.Error(http.StatusInternalServerError, "getWatchedRepos", err)
}
- ctx.JSON(200, &repos)
+ ctx.JSON(http.StatusOK, &repos)
}
// GetMyWatchedRepos returns the repos that the authenticated user is watching
@@ -65,11 +68,12 @@ func GetMyWatchedRepos(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/RepositoryList"
+
repos, err := getWatchedRepos(ctx.User, true)
if err != nil {
- ctx.Error(500, "getWatchedRepos", err)
+ ctx.Error(http.StatusInternalServerError, "getWatchedRepos", err)
}
- ctx.JSON(200, &repos)
+ ctx.JSON(http.StatusOK, &repos)
}
// IsWatching returns whether the authenticated user is watching the repo
@@ -92,8 +96,9 @@ func IsWatching(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/WatchInfo"
+
if models.IsWatching(ctx.User.ID, ctx.Repo.Repository.ID) {
- ctx.JSON(200, api.WatchInfo{
+ ctx.JSON(http.StatusOK, api.WatchInfo{
Subscribed: true,
Ignored: false,
Reason: nil,
@@ -125,12 +130,13 @@ func Watch(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/WatchInfo"
+
err := models.WatchRepo(ctx.User.ID, ctx.Repo.Repository.ID, true)
if err != nil {
- ctx.Error(500, "WatchRepo", err)
+ ctx.Error(http.StatusInternalServerError, "WatchRepo", err)
return
}
- ctx.JSON(200, api.WatchInfo{
+ ctx.JSON(http.StatusOK, api.WatchInfo{
Subscribed: true,
Ignored: false,
Reason: nil,
@@ -160,12 +166,13 @@ func Unwatch(ctx *context.APIContext) {
// responses:
// "204":
// "$ref": "#/responses/empty"
+
err := models.WatchRepo(ctx.User.ID, ctx.Repo.Repository.ID, false)
if err != nil {
- ctx.Error(500, "UnwatchRepo", err)
+ ctx.Error(http.StatusInternalServerError, "UnwatchRepo", err)
return
}
- ctx.Status(204)
+ ctx.Status(http.StatusNoContent)
}
// subscriptionURL returns the URL of the subscription API endpoint of a repo