summaryrefslogtreecommitdiffstats
path: root/routers/api/v1/user/watch.go
diff options
context:
space:
mode:
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