增加站内信未读提醒和后台通知中心+txt 校验
This commit is contained in:
@@ -45,9 +45,40 @@ func (r *Repository) List(ctx context.Context, userID uint64, page, pageSize int
|
||||
|
||||
func (r *Repository) MarkRead(ctx context.Context, userID uint64, id uint64) error {
|
||||
now := time.Now()
|
||||
return r.db.WithContext(ctx).Model(&model.Notification{}).
|
||||
result := r.db.WithContext(ctx).Model(&model.Notification{}).
|
||||
Where("id = ? AND user_id = ?", id, userID).
|
||||
Update("read_at", now).Error
|
||||
Update("read_at", now)
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
}
|
||||
if result.RowsAffected == 0 {
|
||||
var total int64
|
||||
if err := r.db.WithContext(ctx).Model(&model.Notification{}).
|
||||
Where("id = ? AND user_id = ?", id, userID).
|
||||
Count(&total).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if total == 0 {
|
||||
return ErrNotificationNotFound
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Repository) UnreadCount(ctx context.Context, userID uint64) (int64, error) {
|
||||
var total int64
|
||||
err := r.db.WithContext(ctx).Model(&model.Notification{}).
|
||||
Where("user_id = ? AND read_at IS NULL", userID).
|
||||
Count(&total).Error
|
||||
return total, err
|
||||
}
|
||||
|
||||
func (r *Repository) MarkAllRead(ctx context.Context, userID uint64) (int64, error) {
|
||||
now := time.Now()
|
||||
result := r.db.WithContext(ctx).Model(&model.Notification{}).
|
||||
Where("user_id = ? AND read_at IS NULL", userID).
|
||||
Update("read_at", now)
|
||||
return result.RowsAffected, result.Error
|
||||
}
|
||||
|
||||
func Append(tx *gorm.DB, entries ...Entry) error {
|
||||
|
||||
Reference in New Issue
Block a user