From 70899dc4904dab42d53a8f4cda859e8bab58fe28 Mon Sep 17 00:00:00 2001 From: kilo Date: Thu, 16 Nov 2017 19:18:29 +0100 Subject: [PATCH] GetLikings() & GetFollowers() now return count too --- models/user.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/models/user.go b/models/user.go index 5a068b12..d07167e6 100644 --- a/models/user.go +++ b/models/user.go @@ -260,17 +260,19 @@ func (u *User) ToJSON() UserJSON { } // GetLikings : Gets who is followed by the user -func (u *User) GetLikings() { +func (u *User) GetLikings() int { var liked []User ORM.Joins("JOIN user_follows on user_follows.following=?", u.ID).Where("users.user_id = user_follows.user_id").Group("users.user_id").Find(&liked) u.Likings = liked + return len(u.Likings) } // GetFollowers : Gets who is following the user -func (u *User) GetFollowers() { +func (u *User) GetFollowers() int { var likings []User ORM.Joins("JOIN user_follows on user_follows.user_id=?", u.ID).Where("users.user_id = user_follows.following").Group("users.user_id").Find(&likings) u.Followers = likings + return len(u.Followers) } // SetFollow : Makes a user follow another