fix(phase2a): 代码审查修复 - 8项关键/重要问题
安全修复: - WebSocket Token 增加 Redis 有效性校验(已登出用户无法建立 WS) 功能修复: - GetRecommendFriends 改为批量查询,正确返回用户名/昵称/头像 - 上下线通知:OnlineService 通过接口注入获取好友列表推送状态变更 - 管理端在线用户 API 补充用户名信息 代码质量: - 所有 json.Marshal/Redis 错误增加检查与日志 - ContactController 13 个 endpoint 统一走 handleError 业务错误映射 - 管理端 Controller 补全包注释、函数注释和结构化日志 - 前端 5 个联系人页面 avatar 工具函数抽取到 utils/avatar.js Made-with: Cursor
This commit is contained in:
@@ -196,9 +196,11 @@ func (d *FriendshipDAO) BlockUser(ctx context.Context, userID, targetID int64) e
|
||||
zap.Int64("user_id", userID), zap.Int64("target_id", targetID))
|
||||
|
||||
return d.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
tx.Where("(user_id = ? AND friend_id = ?) OR (user_id = ? AND friend_id = ?)",
|
||||
if err := tx.Where("(user_id = ? AND friend_id = ?) OR (user_id = ? AND friend_id = ?)",
|
||||
userID, targetID, targetID, userID).
|
||||
Delete(&model.Friendship{})
|
||||
Delete(&model.Friendship{}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
block := &model.Friendship{
|
||||
UserID: userID,
|
||||
@@ -324,6 +326,23 @@ func (d *FriendshipDAO) GetFriendIDs(ctx context.Context, userID int64) ([]int64
|
||||
return ids, err
|
||||
}
|
||||
|
||||
// GetUsersByIDs 批量查询用户信息(仅返回 id/username/nickname/avatar)
|
||||
func (d *FriendshipDAO) GetUsersByIDs(ctx context.Context, userIDs []int64) ([]authModel.User, error) {
|
||||
funcName := "dao.friendship_dao.GetUsersByIDs"
|
||||
logs.Debug(ctx, funcName, "批量查询用户信息", zap.Int("count", len(userIDs)))
|
||||
|
||||
var users []authModel.User
|
||||
err := d.db.WithContext(ctx).
|
||||
Model(&authModel.User{}).
|
||||
Select("id, username, nickname, avatar").
|
||||
Where("id IN ?", userIDs).
|
||||
Find(&users).Error
|
||||
if err != nil {
|
||||
logs.Error(ctx, funcName, "批量查询用户信息失败", zap.Error(err))
|
||||
}
|
||||
return users, err
|
||||
}
|
||||
|
||||
// CountFriendsByGroup 统计每个分组的好友数
|
||||
func (d *FriendshipDAO) CountFriendsByGroup(ctx context.Context, userID int64) (map[int64]int, error) {
|
||||
type GroupCount struct {
|
||||
|
||||
Reference in New Issue
Block a user