using Helpdesk.Application.Abstractions; using Helpdesk.Application.Common; using Microsoft.EntityFrameworkCore; namespace Helpdesk.Application.Notifications; public sealed class PushDeviceService(IAppDbContext db, ICurrentUser currentUser) { public Task RegisterAsync(string token, CancellationToken ct) { ValidateToken(token); return db.RegisterPushDeviceAsync(currentUser.Id, token, ct); } public async Task UnregisterAsync(string token, CancellationToken ct) { ValidateToken(token); var userId = currentUser.Id; await db.PushDevices.Where(d => d.UserId == userId && d.FcmToken == token).ExecuteDeleteAsync(ct); } private static void ValidateToken(string? token) { if (string.IsNullOrEmpty(token) || token.Length > 512 || token.Any(c => char.IsWhiteSpace(c) || char.IsControl(c))) throw new BadRequestException("Neplatný registrační token zařízení."); } }