mirror of https://github.com/gogits/gogs.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
121 lines
2.8 KiB
121 lines
2.8 KiB
9 years ago
|
// Copyright 2015 The Gogs Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
|
package user
|
||
|
|
||
|
import (
|
||
|
api "github.com/gogits/go-gogs-client"
|
||
|
|
||
|
"github.com/gogits/gogs/models"
|
||
8 years ago
|
"github.com/gogits/gogs/pkg/context"
|
||
9 years ago
|
)
|
||
|
|
||
8 years ago
|
func responseApiUsers(c *context.APIContext, users []*models.User) {
|
||
9 years ago
|
apiUsers := make([]*api.User, len(users))
|
||
|
for i := range users {
|
||
8 years ago
|
apiUsers[i] = users[i].APIFormat()
|
||
9 years ago
|
}
|
||
8 years ago
|
c.JSON(200, &apiUsers)
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
func listUserFollowers(c *context.APIContext, u *models.User) {
|
||
|
users, err := u.GetFollowers(c.QueryInt("page"))
|
||
9 years ago
|
if err != nil {
|
||
8 years ago
|
c.Error(500, "GetUserFollowers", err)
|
||
9 years ago
|
return
|
||
|
}
|
||
8 years ago
|
responseApiUsers(c, users)
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
func ListMyFollowers(c *context.APIContext) {
|
||
|
listUserFollowers(c, c.User)
|
||
9 years ago
|
}
|
||
|
|
||
|
// https://github.com/gogits/go-gogs-client/wiki/Users-Followers#list-followers-of-a-user
|
||
8 years ago
|
func ListFollowers(c *context.APIContext) {
|
||
|
u := GetUserByParams(c)
|
||
|
if c.Written() {
|
||
9 years ago
|
return
|
||
|
}
|
||
8 years ago
|
listUserFollowers(c, u)
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
func listUserFollowing(c *context.APIContext, u *models.User) {
|
||
|
users, err := u.GetFollowing(c.QueryInt("page"))
|
||
9 years ago
|
if err != nil {
|
||
8 years ago
|
c.Error(500, "GetFollowing", err)
|
||
9 years ago
|
return
|
||
|
}
|
||
8 years ago
|
responseApiUsers(c, users)
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
func ListMyFollowing(c *context.APIContext) {
|
||
|
listUserFollowing(c, c.User)
|
||
9 years ago
|
}
|
||
|
|
||
|
// https://github.com/gogits/go-gogs-client/wiki/Users-Followers#list-users-followed-by-another-user
|
||
8 years ago
|
func ListFollowing(c *context.APIContext) {
|
||
|
u := GetUserByParams(c)
|
||
|
if c.Written() {
|
||
9 years ago
|
return
|
||
|
}
|
||
8 years ago
|
listUserFollowing(c, u)
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
func checkUserFollowing(c *context.APIContext, u *models.User, followID int64) {
|
||
9 years ago
|
if u.IsFollowing(followID) {
|
||
8 years ago
|
c.Status(204)
|
||
9 years ago
|
} else {
|
||
8 years ago
|
c.Status(404)
|
||
9 years ago
|
}
|
||
|
}
|
||
|
|
||
|
// https://github.com/gogits/go-gogs-client/wiki/Users-Followers#check-if-you-are-following-a-user
|
||
8 years ago
|
func CheckMyFollowing(c *context.APIContext) {
|
||
|
target := GetUserByParams(c)
|
||
|
if c.Written() {
|
||
9 years ago
|
return
|
||
|
}
|
||
8 years ago
|
checkUserFollowing(c, c.User, target.ID)
|
||
9 years ago
|
}
|
||
|
|
||
|
// https://github.com/gogits/go-gogs-client/wiki/Users-Followers#check-if-one-user-follows-another
|
||
8 years ago
|
func CheckFollowing(c *context.APIContext) {
|
||
|
u := GetUserByParams(c)
|
||
|
if c.Written() {
|
||
9 years ago
|
return
|
||
|
}
|
||
8 years ago
|
target := GetUserByParamsName(c, ":target")
|
||
|
if c.Written() {
|
||
9 years ago
|
return
|
||
|
}
|
||
8 years ago
|
checkUserFollowing(c, u, target.ID)
|
||
9 years ago
|
}
|
||
|
|
||
|
// https://github.com/gogits/go-gogs-client/wiki/Users-Followers#follow-a-user
|
||
8 years ago
|
func Follow(c *context.APIContext) {
|
||
|
target := GetUserByParams(c)
|
||
|
if c.Written() {
|
||
9 years ago
|
return
|
||
|
}
|
||
8 years ago
|
if err := models.FollowUser(c.User.ID, target.ID); err != nil {
|
||
|
c.Error(500, "FollowUser", err)
|
||
9 years ago
|
return
|
||
|
}
|
||
8 years ago
|
c.Status(204)
|
||
9 years ago
|
}
|
||
|
|
||
|
// https://github.com/gogits/go-gogs-client/wiki/Users-Followers#unfollow-a-user
|
||
8 years ago
|
func Unfollow(c *context.APIContext) {
|
||
|
target := GetUserByParams(c)
|
||
|
if c.Written() {
|
||
9 years ago
|
return
|
||
|
}
|
||
8 years ago
|
if err := models.UnfollowUser(c.User.ID, target.ID); err != nil {
|
||
|
c.Error(500, "UnfollowUser", err)
|
||
9 years ago
|
return
|
||
|
}
|
||
8 years ago
|
c.Status(204)
|
||
9 years ago
|
}
|