|
|
@ -600,27 +600,27 @@ type Follow struct {
|
|
|
|
|
|
|
|
|
|
|
|
// FollowUser marks someone be another's follower.
|
|
|
|
// FollowUser marks someone be another's follower.
|
|
|
|
func FollowUser(userId int64, followId int64) (err error) {
|
|
|
|
func FollowUser(userId int64, followId int64) (err error) {
|
|
|
|
session := x.NewSession()
|
|
|
|
sess := x.NewSession()
|
|
|
|
defer session.Close()
|
|
|
|
defer sess.Close()
|
|
|
|
session.Begin()
|
|
|
|
sess.Begin()
|
|
|
|
|
|
|
|
|
|
|
|
if _, err = session.Insert(&Follow{UserId: userId, FollowId: followId}); err != nil {
|
|
|
|
if _, err = sess.Insert(&Follow{UserId: userId, FollowId: followId}); err != nil {
|
|
|
|
session.Rollback()
|
|
|
|
sess.Rollback()
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
rawSql := "UPDATE `user` SET num_followers = num_followers + 1 WHERE id = ?"
|
|
|
|
rawSql := "UPDATE `user` SET num_followers = num_followers + 1 WHERE id = ?"
|
|
|
|
if _, err = session.Exec(rawSql, followId); err != nil {
|
|
|
|
if _, err = sess.Exec(rawSql, followId); err != nil {
|
|
|
|
session.Rollback()
|
|
|
|
sess.Rollback()
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
rawSql = "UPDATE `user` SET num_followings = num_followings + 1 WHERE id = ?"
|
|
|
|
rawSql = "UPDATE `user` SET num_followings = num_followings + 1 WHERE id = ?"
|
|
|
|
if _, err = session.Exec(rawSql, userId); err != nil {
|
|
|
|
if _, err = sess.Exec(rawSql, userId); err != nil {
|
|
|
|
session.Rollback()
|
|
|
|
sess.Rollback()
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return session.Commit()
|
|
|
|
return sess.Commit()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// UnFollowUser unmarks someone be another's follower.
|
|
|
|
// UnFollowUser unmarks someone be another's follower.
|
|
|
|