MCPcopy Create free account
hub / github.com/GoSimplicity/LinkMe / FollowUser

Method FollowUser

internal/repository/dao/relation.go:96–131  ·  view source on GitHub ↗

FollowUser 关注用户,并更新相关计数器

(ctx context.Context, followerID, followeeID int64)

Source from the content-addressed store, hash-verified

94
95// FollowUser 关注用户,并更新相关计数器
96func (r *relationDAO) FollowUser(ctx context.Context, followerID, followeeID int64) error {
97 now := r.getCurrentTime()
98
99 err := r.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
100 // 创建Relation记录
101 newRelation := &Relation{
102 FollowerID: followerID,
103 FolloweeID: followeeID,
104 Status: FollowStatus,
105 CreatedAt: now,
106 UpdatedAt: now,
107 }
108 if err := tx.Create(newRelation).Error; err != nil {
109 return err
110 }
111
112 // 更新关注者的关注数
113 if err := r.updateRelationCount(tx, followerID, "followee_count", 1, now); err != nil {
114 return err
115 }
116
117 // 更新被关注者的粉丝数
118 if err := r.updateRelationCount(tx, followeeID, "follower_count", 1, now); err != nil {
119 return err
120 }
121
122 return nil
123 })
124
125 if err != nil {
126 r.l.Error("failed to follow user", zap.Error(err))
127 return err
128 }
129
130 return nil
131}
132
133// CancelFollowUser 取消关注用户,并更新相关计数器
134func (r *relationDAO) CancelFollowUser(ctx context.Context, followerID, followeeID int64) error {

Callers

nothing calls this directly

Calls 3

getCurrentTimeMethod · 0.95
updateRelationCountMethod · 0.95
CreateMethod · 0.65

Tested by

no test coverage detected