feat(notification): 新增全部标记已读接口
This commit is contained in:
@@ -108,6 +108,26 @@ func (s *NotificationService) Read(ctx context.Context, userID int64, request *d
|
||||
return &dto.NotificationUnreadResponse{UnreadCount: cnt}, nil
|
||||
}
|
||||
|
||||
// ReadAll 将当前用户全部未读通知标记为已读,并回填未读数缓存。
|
||||
// 与单条已读一致:以 MySQL 为权威重新统计后返回,避免 Redis 计数偏差。
|
||||
func (s *NotificationService) ReadAll(ctx context.Context, userID int64) (*dto.NotificationUnreadResponse, *errcode.Error) {
|
||||
ctx, span := global.Tracer.Start(ctx, "svc.NotificationReadAll")
|
||||
defer span.End()
|
||||
|
||||
affected, err := s.notificationDao.NotificationUpdateReadAllByUserID(ctx, userID)
|
||||
if err != nil {
|
||||
slog.ErrorContext(ctx, "mark all notifications read failed", "user_id", userID, "error", err)
|
||||
return nil, errcode.DatabaseError
|
||||
}
|
||||
slog.InfoContext(ctx, "mark all notifications read", "user_id", userID, "affected", affected)
|
||||
|
||||
cnt, cerr := s.unreadCount(ctx, userID)
|
||||
if cerr != nil {
|
||||
return nil, cerr
|
||||
}
|
||||
return &dto.NotificationUnreadResponse{UnreadCount: cnt}, nil
|
||||
}
|
||||
|
||||
// Unread 获取当前用户未读数(以 MySQL 为权威)。
|
||||
func (s *NotificationService) Unread(ctx context.Context, userID int64) (*dto.NotificationUnreadResponse, *errcode.Error) {
|
||||
ctx, span := global.Tracer.Start(ctx, "svc.NotificationUnread")
|
||||
|
||||
Reference in New Issue
Block a user