feat: implement cross-device reading progress synchronization using SignalR and remove legacy quiz generation services.

This commit is contained in:
2026-05-02 19:55:07 +02:00
parent e5611758f1
commit 94ecc7a404
22 changed files with 332 additions and 69 deletions
@@ -0,0 +1,46 @@
using FluentResults;
using MediatR;
using Microsoft.AspNetCore.SignalR;
using Microsoft.EntityFrameworkCore;
using NexusReader.Application.Commands.Sync;
using NexusReader.Domain.Entities;
using NexusReader.Infrastructure.Persistence;
using NexusReader.Infrastructure.RealTime;
namespace NexusReader.Infrastructure.Handlers;
public class UpdateReadingProgressCommandHandler : IRequestHandler<UpdateReadingProgressCommand, Result>
{
private readonly AppDbContext _context;
private readonly IHubContext<SyncHub> _hubContext;
public UpdateReadingProgressCommandHandler(
AppDbContext context,
IHubContext<SyncHub> hubContext)
{
_context = context;
_hubContext = hubContext;
}
public async Task<Result> Handle(UpdateReadingProgressCommand request, CancellationToken cancellationToken)
{
var user = await _context.Users.FirstOrDefaultAsync(u => u.Id == request.UserId, cancellationToken);
if (user == null)
{
return Result.Fail("User not found.");
}
var now = DateTime.UtcNow;
user.LastReadPageId = request.PageId;
user.LastReadAt = now;
await _context.SaveChangesAsync(cancellationToken);
// Broadcast to other devices
await _hubContext.Clients
.Group($"User_{request.UserId}")
.SendAsync("ProgressUpdated", request.PageId, now, cancellationToken);
return Result.Ok();
}
}