feat(notification): 新增全部标记已读接口
This commit is contained in:
@@ -60,6 +60,22 @@ func (d *NotificationDao) NotificationUpdateReadByUUIDIfUnread(ctx context.Conte
|
||||
return res.RowsAffected > 0, nil
|
||||
}
|
||||
|
||||
// NotificationUpdateReadAllByUserID 将该用户全部未读通知标记为已读,返回影响行数。
|
||||
// 条件带 is_read = 1,保证只统计本次真正从未读变为已读的条数(幂等,重复调用返回 0)。
|
||||
func (d *NotificationDao) NotificationUpdateReadAllByUserID(ctx context.Context, userID int64) (int64, error) {
|
||||
ctx, span := global.Tracer.Start(ctx, "mysqldao.NotificationUpdateReadAllByUserID")
|
||||
defer span.End()
|
||||
|
||||
res := d.db.WithContext(ctx).Model(&mysqlmodel.UserNotification{}).
|
||||
Where("user_id = ? AND is_read = ?", userID, int8(1)).
|
||||
Update("is_read", int8(2))
|
||||
if res.Error != nil {
|
||||
span.RecordError(res.Error)
|
||||
return 0, res.Error
|
||||
}
|
||||
return res.RowsAffected, nil
|
||||
}
|
||||
|
||||
// NotificationGetByUUID 按 UUID 查询通知
|
||||
func (d *NotificationDao) NotificationGetByUUID(ctx context.Context, notificationUUID string) (*mysqlmodel.UserNotification, error) {
|
||||
ctx, span := global.Tracer.Start(ctx, "mysqldao.NotificationGetByUUID")
|
||||
|
||||
Reference in New Issue
Block a user