diff options
Diffstat (limited to 'routers/api/v1/user/follower.go')
-rw-r--r-- | routers/api/v1/user/follower.go | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/routers/api/v1/user/follower.go b/routers/api/v1/user/follower.go index ec512b9806..bd68070265 100644 --- a/routers/api/v1/user/follower.go +++ b/routers/api/v1/user/follower.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" @@ -16,13 +18,13 @@ func responseAPIUsers(ctx *context.APIContext, users []*models.User) { for i := range users { apiUsers[i] = convert.ToUser(users[i], ctx.IsSigned, ctx.User != nil && ctx.User.IsAdmin) } - ctx.JSON(200, &apiUsers) + ctx.JSON(http.StatusOK, &apiUsers) } func listUserFollowers(ctx *context.APIContext, u *models.User) { users, err := u.GetFollowers(ctx.QueryInt("page")) if err != nil { - ctx.Error(500, "GetUserFollowers", err) + ctx.Error(http.StatusInternalServerError, "GetUserFollowers", err) return } responseAPIUsers(ctx, users) @@ -38,6 +40,7 @@ func ListMyFollowers(ctx *context.APIContext) { // responses: // "200": // "$ref": "#/responses/UserList" + listUserFollowers(ctx, ctx.User) } @@ -57,6 +60,7 @@ func ListFollowers(ctx *context.APIContext) { // responses: // "200": // "$ref": "#/responses/UserList" + u := GetUserByParams(ctx) if ctx.Written() { return @@ -67,7 +71,7 @@ func ListFollowers(ctx *context.APIContext) { func listUserFollowing(ctx *context.APIContext, u *models.User) { users, err := u.GetFollowing(ctx.QueryInt("page")) if err != nil { - ctx.Error(500, "GetFollowing", err) + ctx.Error(http.StatusInternalServerError, "GetFollowing", err) return } responseAPIUsers(ctx, users) @@ -83,6 +87,7 @@ func ListMyFollowing(ctx *context.APIContext) { // responses: // "200": // "$ref": "#/responses/UserList" + listUserFollowing(ctx, ctx.User) } @@ -102,6 +107,7 @@ func ListFollowing(ctx *context.APIContext) { // responses: // "200": // "$ref": "#/responses/UserList" + u := GetUserByParams(ctx) if ctx.Written() { return @@ -111,7 +117,7 @@ func ListFollowing(ctx *context.APIContext) { func checkUserFollowing(ctx *context.APIContext, u *models.User, followID int64) { if u.IsFollowing(followID) { - ctx.Status(204) + ctx.Status(http.StatusNoContent) } else { ctx.NotFound() } @@ -133,6 +139,7 @@ func CheckMyFollowing(ctx *context.APIContext) { // "$ref": "#/responses/empty" // "404": // "$ref": "#/responses/notFound" + target := GetUserByParams(ctx) if ctx.Written() { return @@ -161,6 +168,7 @@ func CheckFollowing(ctx *context.APIContext) { // "$ref": "#/responses/empty" // "404": // "$ref": "#/responses/notFound" + u := GetUserByParams(ctx) if ctx.Written() { return @@ -186,15 +194,16 @@ func Follow(ctx *context.APIContext) { // responses: // "204": // "$ref": "#/responses/empty" + target := GetUserByParams(ctx) if ctx.Written() { return } if err := models.FollowUser(ctx.User.ID, target.ID); err != nil { - ctx.Error(500, "FollowUser", err) + ctx.Error(http.StatusInternalServerError, "FollowUser", err) return } - ctx.Status(204) + ctx.Status(http.StatusNoContent) } // Unfollow unfollow a user @@ -211,13 +220,14 @@ func Unfollow(ctx *context.APIContext) { // responses: // "204": // "$ref": "#/responses/empty" + target := GetUserByParams(ctx) if ctx.Written() { return } if err := models.UnfollowUser(ctx.User.ID, target.ID); err != nil { - ctx.Error(500, "UnfollowUser", err) + ctx.Error(http.StatusInternalServerError, "UnfollowUser", err) return } - ctx.Status(204) + ctx.Status(http.StatusNoContent) } |