Refactor: migrate Core -> Domain and reorganize projects

Large refactor that renames/moves core types into a new Govor.Domain surface and reorganizes the Application layer. Models, configurations, migrations and many files moved from Govor.Core/Govor.Data to Govor.Domain; numerous Application services, interfaces and implementations were relocated or added (authentication, friends, messages, medias, push notifications, user sessions, storage, synching, private chats, etc.). Tests updated to use Govor.Domain namespaces and adjusted project references (removed Govor.Data reference from API tests). Also updated API, Hub and mapping code and project files to reflect the new structure and naming. This is primarily a codebase-wide namespace and module reorganization to establish a Domain project and restructure application services.
This commit is contained in:
Artemy
2026-07-16 19:27:45 +07:00
parent 1d35356c8c
commit 6d1c53beeb
371 changed files with 2729 additions and 6694 deletions
@@ -0,0 +1,6 @@
namespace Govor.Application.Users;
public interface IUserNameExistValidator
{
Task<bool> IsUsernameExistsAsync(string userName);
}
@@ -0,0 +1,26 @@
using Govor.Domain;
using Microsoft.EntityFrameworkCore;
namespace Govor.Application.Users;
public class UserNameExistValidator : IUserNameExistValidator
{
private readonly GovorDbContext _context;
public UserNameExistValidator(GovorDbContext context)
{
_context = context;
}
public async Task<bool> IsUsernameExistsAsync(string userName)
{
if (string.IsNullOrWhiteSpace(userName))
{
return false;
}
return await _context.Users
.AsNoTracking()
.AnyAsync(u => u.Username == userName);
}
}
@@ -0,0 +1,10 @@
namespace Govor.Application.Users.UserOnlineStatus;
public interface IOnlineUserStore
{
bool AddConnection(Guid userId, string connectionId);
bool RemoveConnection(Guid userId, string connectionId);
bool IsOnline(Guid userId);
IEnumerable<string> GetConnections(Guid userId);
IReadOnlyCollection<Guid> GetAllOnlineUsers();
}
@@ -0,0 +1,6 @@
namespace Govor.Application.Users.UserOnlineStatus;
public interface IUserNotificationScopeService
{
Task<List<Guid>> GetNotifiedUsers(Guid userId);
}
@@ -0,0 +1,6 @@
namespace Govor.Application.Users.UserOnlineStatus;
public interface IUserPresenceReader
{
Task<DateTime?> GetLastSeenAsync(Guid userId);
}
@@ -0,0 +1,71 @@
using System.Collections.Concurrent;
namespace Govor.Application.Users.UserOnlineStatus;
public class OnlineUserStore : IOnlineUserStore
{
private readonly ConcurrentDictionary<Guid, HashSet<string>> _userConnections = new();
public bool AddConnection(Guid userId, string connectionId)
{
bool isFirstConnection = false;
_userConnections.AddOrUpdate(userId,
_ => {
isFirstConnection = true;
return new HashSet<string> { connectionId };
},
(_, connections) => {
lock (connections)
{
if (connections.Count == 0) isFirstConnection = true;
connections.Add(connectionId);
}
return connections;
});
return isFirstConnection;
}
public bool RemoveConnection(Guid userId, string connectionId)
{
bool isLastConnection = false;
if (_userConnections.TryGetValue(userId, out var connections))
{
lock (connections)
{
connections.Remove(connectionId);
if (connections.Count == 0)
{
isLastConnection = true;
_userConnections.TryRemove(userId, out _);
}
}
}
return isLastConnection;
}
public IEnumerable<string> GetConnections(Guid userId)
{
if (_userConnections.TryGetValue(userId, out var connections))
{
lock (connections)
{
return connections.ToList();
}
}
return Enumerable.Empty<string>();
}
public bool IsOnline(Guid userId)
{
return _userConnections.TryGetValue(userId, out var connections) && connections.Count > 0;
}
public IReadOnlyCollection<Guid> GetAllOnlineUsers()
{
return _userConnections.Keys.ToList();
}
}
@@ -0,0 +1,44 @@
using Govor.Application.Friends;
using Microsoft.Extensions.Logging;
namespace Govor.Application.Users.UserOnlineStatus;
public class UserNotificationScopeService : IUserNotificationScopeService
{
private readonly ILogger<UserNotificationScopeService> _logger;
private readonly IFriendshipService _friendships;
public UserNotificationScopeService(ILogger<UserNotificationScopeService> logger, IFriendshipService friendships)
{
_logger = logger;
_friendships = friendships;
}
public async Task<List<Guid>> GetNotifiedUsers(Guid userId)
{
_logger.LogInformation($"Getting notified users of online/offline action user {userId}");
var users = await _friendships.GetFriendsAsync(userId);
return users.Select(u => u.Id).ToList();
}
/*public async Task SetWasOnlineAsync(Guid userId, DateTime when)
{
try
{
_logger.LogInformation("Set was-online for user {UserId}", userId);
var user = await _users.FindByIdAsync(userId);
user.WasOnline = when;
await _users.UpdateAsync(user);
}
catch (NotFoundByKeyException<Guid> ex)
{
_logger.LogError(ex, ex.Message);
throw new InvalidOperationException("User not found");
}
catch (UpdateException ex)
{
_logger.LogError(ex, "Failed to set WasOnline for user {UserId} at {Time}", userId, when);
throw new InvalidOperationException("Something went wrong when trying to set was-online for user");
}
}*/
}
@@ -0,0 +1,9 @@
namespace Govor.Application.Users.UserOnlineStatus;
public class UserPresenceReader : IUserPresenceReader
{
public Task<DateTime?> GetLastSeenAsync(Guid userId)
{
throw new NotImplementedException();
}
}
@@ -0,0 +1,8 @@
namespace Govor.Application.Users.UserSessions.Crypto;
public interface IOneTimePreKeysRotator
{
Task RotateOneTimePreKeysAsync(Guid sessionId, IEnumerable<byte[]> newOneTimePreKeys);
Task MarkOneTimePreKeyAsUsedAsync(Guid sessionId, Guid oneTimePreKeyId);
}
@@ -0,0 +1,13 @@
using Govor.Domain.Models.Users.Crypto;
namespace Govor.Application.Users.UserSessions.Crypto;
public interface ISessionKeyAttacher
{
Task AttachKeysAsync(
Guid sessionId,
byte[] identityKey,
byte[] signedPreKey,
byte[] signedPreKeySignature,
IEnumerable<byte[]> oneTimePreKeys);
}
@@ -0,0 +1,11 @@
using Govor.Domain.Models.Users.Crypto;
namespace Govor.Application.Users.UserSessions.Crypto;
public interface ISessionKeysReader
{
Task<bool> HasKeysAttachedAsync(Guid sessionId);
Task<IReadOnlyList<UserCryptoSession>> GetAllActiveKeysAsync(Guid userId);
Task<int> GetRemainingOneTimePreKeysCountAsync(Guid sessionId);
Task<UserCryptoSession?> GetKeysBySessionIdAsync(Guid sessionId);
}
@@ -0,0 +1,69 @@
using Govor.Application.Infrastructure.Extensions;
using Govor.Domain.Models.Users.Crypto;
using Govor.Domain;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
namespace Govor.Application.Users.UserSessions.Crypto;
public class OneTimePreKeysRotator : IOneTimePreKeysRotator
{
private readonly ILogger<SessionKeyAttacher> _logger;
private readonly ICurrentUserService _current;
private readonly GovorDbContext _context;
public OneTimePreKeysRotator(ILogger<SessionKeyAttacher> logger, ICurrentUserService current, GovorDbContext context)
{
_logger = logger;
_current = current;
_context = context;
}
public async Task RotateOneTimePreKeysAsync(Guid sessionId, IEnumerable<byte[]> newOneTimePreKeys)
{
var cryptoSession = await _context.UserCryptoSessions
.Include(c => c.OneTimePreKeys)
.FirstOrDefaultAsync(c => c.UserSessionId == sessionId);
if (cryptoSession == null)
throw new ArgumentException("Crypto session not found", nameof(sessionId));
// Удаляем все использованные ключи
var usedKeys = cryptoSession.OneTimePreKeys.Where(k => k.IsUsed).ToList();
if (usedKeys.Any())
{
_context.OneTimePreKeys.RemoveRange(usedKeys);
}
// Добавляем новые ключи (возможно, стоит ограничить количество)
foreach (var key in newOneTimePreKeys)
{
cryptoSession.OneTimePreKeys.Add(new OneTimePreKey
{
Id = Guid.NewGuid(),
PublicKey = key,
IsUsed = false,
UploadedAt = DateTime.UtcNow
});
}
await _context.SaveChangesAsync();
}
public async Task MarkOneTimePreKeyAsUsedAsync(Guid sessionId, Guid oneTimePreKeyId)
{
var key = await _context.OneTimePreKeys
.Include(k => k.UserCryptoSession)
.FirstOrDefaultAsync(k => k.Id == oneTimePreKeyId && k.UserCryptoSession.UserSessionId == sessionId);
if (key == null)
throw new ArgumentException("One-Time PreKey not found for this session", nameof(oneTimePreKeyId));
if (key.IsUsed)
return; // Уже помечен
key.IsUsed = true;
await _context.SaveChangesAsync();
}
}
@@ -0,0 +1,72 @@
using Govor.Application.Infrastructure.Extensions;
using Govor.Domain.Models.Users.Crypto;
using Govor.Domain;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
namespace Govor.Application.Users.UserSessions.Crypto;
public class SessionKeyAttacher : ISessionKeyAttacher
{
private readonly ILogger<SessionKeyAttacher> _logger;
private readonly ICurrentUserService _current;
private readonly GovorDbContext _context;
public SessionKeyAttacher(ILogger<SessionKeyAttacher> logger, ICurrentUserService current, GovorDbContext context)
{
_logger = logger;
_current = current;
_context = context;
}
public async Task AttachKeysAsync(
Guid sessionId,
byte[] identityKey,
byte[] signedPreKey,
byte[] signedPreKeySignature,
IEnumerable<byte[]> oneTimePreKeys)
{
var session = await _context.UserSessions
.Include(s => s.CryptoSession)
.ThenInclude(c => c.OneTimePreKeys)
.FirstOrDefaultAsync(s => s.Id == sessionId);
if (session == null)
throw new ArgumentException("Session not found", nameof(sessionId));
if (session.CryptoSession != null)
throw new InvalidOperationException("Keys are already attached to this session");
if(session.UserId != _current.GetCurrentUserId())
throw new InvalidOperationException("You cannot attach keys to this session");
var cryptoSessionId = Guid.NewGuid();
var cryptoSession = new UserCryptoSession
{
Id = cryptoSessionId,
UserSessionId = sessionId,
PublicIdentityKey = identityKey,
SignedPreKey = new SignedPreKey()
{
Id = Guid.NewGuid(),
UserCryptoSessionId = cryptoSessionId,
PublicSignedPreKey = signedPreKey,
SignedPreKeySignature = signedPreKeySignature,
},
OneTimePreKeys = oneTimePreKeys.Select(key => new OneTimePreKey
{
Id = Guid.NewGuid(),
PublicKey = key,
IsUsed = false,
UploadedAt = DateTime.UtcNow
}).ToList()
};
session.CryptoSession = cryptoSession;
await _context.SaveChangesAsync();
_logger.LogInformation("Attached keys to session {SessionId}", sessionId);
}
}
@@ -0,0 +1,60 @@
using Govor.Domain.Models.Users.Crypto;
using Govor.Domain;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
namespace Govor.Application.Users.UserSessions.Crypto;
public class SessionKeysReader : ISessionKeysReader
{
private readonly ILogger<SessionKeyAttacher> _logger;
private readonly GovorDbContext _context;
public SessionKeysReader(ILogger<SessionKeyAttacher> logger, GovorDbContext context)
{
_logger = logger;
_context = context;
}
public async Task<bool> HasKeysAttachedAsync(Guid sessionId)
{
return await _context.UserCryptoSessions.AnyAsync(c => c.UserSessionId == sessionId);
}
public async Task<IReadOnlyList<UserCryptoSession>> GetAllActiveKeysAsync(Guid userId)
{
_logger.LogInformation("Getting all active keys for user {UserId}.", userId);
var now = DateTime.UtcNow;
return await _context.UserCryptoSessions
.AsNoTracking()
.Include(c => c.OneTimePreKeys)
.Include(c => c.UserSession)
.Where(c => c.UserSession.UserId == userId
&& !c.UserSession.IsRevoked
&& c.UserSession.ExpiresAt > now)
.ToListAsync();
}
public async Task<int> GetRemainingOneTimePreKeysCountAsync(Guid sessionId)
{
_logger.LogInformation("Getting count of one time pre keys for session {UserId}.", sessionId);
return await _context.OneTimePreKeys
.AsNoTracking()
.Include(f => f.UserCryptoSession)
.CountAsync(f => f.UserCryptoSession.UserSessionId == sessionId);
}
public async Task<UserCryptoSession?> GetKeysBySessionIdAsync(Guid sessionId)
{
_logger.LogInformation("Getting keys for session {session}.", sessionId);
return await _context.UserCryptoSessions
.AsNoTracking()
.Include(c => c.OneTimePreKeys)
.Include(c => c.UserSession)
.FirstOrDefaultAsync(c => c.UserSessionId == sessionId);
}
}
@@ -0,0 +1,11 @@
using Govor.Domain.Common;
using Govor.Domain.Models.Users;
namespace Govor.Application.Users.UserSessions;
public interface IUserSessionOpener
{
Task<Result<RefreshResult>> OpenSessionAsync(User user, string deviceInfo);
}
@@ -0,0 +1,8 @@
using Govor.Domain.Common;
namespace Govor.Application.Users.UserSessions;
public interface IUserSessionReader
{
Task<Result<List<Domain.Models.Users.UserSession>>> GetAllSessionsAsync(Guid userId);
}
@@ -0,0 +1,8 @@
using Govor.Domain.Common;
namespace Govor.Application.Users.UserSessions;
public interface IUserSessionRefresher
{
Task<Result<RefreshResult>> RefreshTokenAsync(string refreshToken);
}
@@ -0,0 +1,10 @@
using Govor.Domain.Common;
namespace Govor.Application.Users.UserSessions;
public interface IUserSessionRevoker
{
Task<Result> CloseSessionByIdAsync(Guid sessionId, Guid userId);
Task<Result> CloseAllSessionsAsync(Guid userId);
}
@@ -0,0 +1,3 @@
namespace Govor.Application.Users.UserSessions;
public record RefreshResult(string refreshToken, string accessToken);
@@ -0,0 +1,122 @@
using Govor.Application.Authentication.JWT;
using Govor.Domain;
using Govor.Domain.Common; // Путь к вашему Result и Error
using Govor.Domain.Models.Users;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace Govor.Application.Users.UserSessions;
public class UserSessionOpener : IUserSessionOpener
{
private readonly ILogger<UserSessionOpener> _logger;
private readonly IUserSessionReader _userSessionReader;
private readonly GovorDbContext _context;
private readonly IJwtTokenHasher _jwtTokenHasher;
private readonly JwtRefreshOption _options;
private readonly IJwtService _jwtService;
public UserSessionOpener(
ILogger<UserSessionOpener> logger,
IUserSessionReader userSessionReader,
GovorDbContext context,
IJwtTokenHasher jwtTokenHasher,
IOptions<JwtRefreshOption> options,
IJwtService jwtService)
{
_logger = logger;
_userSessionReader = userSessionReader;
_context = context;
_jwtTokenHasher = jwtTokenHasher;
_options = options.Value;
_jwtService = jwtService;
}
public async Task<Result<RefreshResult>> OpenSessionAsync(User user, string deviceInfo)
{
_logger.LogInformation("Opening session for user {UserId} on device '{DeviceInfo}'", user.Id, deviceInfo);
var result = await _userSessionReader.GetAllSessionsAsync(user.Id);
if (result.IsFailure)
{
_logger.LogError("Failed to fetch sessions for user {UserId}: {Error}", user.Id, result.Error.Message);
return Result<RefreshResult>.Failure(result.Error);
}
var sessions = result.Value;
var existingSession = sessions.FirstOrDefault(s => s.DeviceInfo == deviceInfo);
try
{
RefreshResult refreshResult;
if (existingSession is not null)
{
refreshResult = await UpdateExistingSessionAsync(user, deviceInfo, existingSession);
}
else
{
refreshResult = await CreateNewSessionAsync(user, deviceInfo);
}
await _context.SaveChangesAsync();
return refreshResult;
}
catch (Exception ex)
{
_logger.LogError(ex, "Database error while opening session for user {UserId}", user.Id);
return Result<RefreshResult>.Failure(ex);
}
}
private async Task<RefreshResult> UpdateExistingSessionAsync(User user, string deviceInfo, UserSession session)
{
var (accessToken, refreshToken) = await GenerateTokensAsync(user, session.Id);
var newTokenHash = _jwtTokenHasher.HashToken(refreshToken);
var newExpiresAt = DateTime.UtcNow.AddDays(_options.RefreshTokenLifetimeDays);
session.RefreshTokenHash = newTokenHash;
session.ExpiresAt = newExpiresAt;
session.CreatedAt = DateTime.UtcNow;
session.IsRevoked = false;
_logger.LogInformation("Updated session for user {UserId} on device '{DeviceInfo}'", user.Id, deviceInfo);
return new RefreshResult(refreshToken, accessToken);
}
private async Task<RefreshResult> CreateNewSessionAsync(User user, string deviceInfo)
{
var sessionId = Guid.NewGuid();
var (accessToken, refreshToken) = await GenerateTokensAsync(user, sessionId);
var refreshTokenHash = _jwtTokenHasher.HashToken(refreshToken);
var newSession = new UserSession
{
Id = sessionId,
UserId = user.Id,
DeviceInfo = deviceInfo,
RefreshTokenHash = refreshTokenHash,
CreatedAt = DateTime.UtcNow,
ExpiresAt = DateTime.UtcNow.AddDays(_options.RefreshTokenLifetimeDays),
IsRevoked = false
};
await _context.UserSessions.AddAsync(newSession);
_logger.LogInformation("Created new session {SessionId} for user {UserId} on device '{DeviceInfo}'", sessionId, user.Id, deviceInfo);
return new RefreshResult(refreshToken, accessToken);
}
private async Task<(string accessToken, string refreshToken)> GenerateTokensAsync(User user, Guid sessionId)
{
var accessToken = await _jwtService.GenerateAccessTokenAsync(user, sessionId);
var refreshToken = await _jwtService.GenerateRefreshTokenAsync(user);
return (accessToken, refreshToken);
}
}
@@ -0,0 +1,46 @@
using Govor.Domain;
using Govor.Domain.Common;
using Govor.Domain.Models.Users;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
namespace Govor.Application.Users.UserSessions;
public class UserSessionReader : IUserSessionReader
{
private readonly GovorDbContext _context;
private readonly ILogger<UserSessionReader> _logger;
public UserSessionReader(GovorDbContext context, ILogger<UserSessionReader> logger)
{
_context = context;
_logger = logger;
}
public async Task<Result<List<UserSession>>> GetAllSessionsAsync(Guid userId)
{
if (userId == Guid.Empty)
{
return Result<List<UserSession>>.Failure(new Error(
"UserSession.InvalidUserId",
"Provided User ID cannot be empty."));
}
_logger.LogInformation("Getting all active sessions for user {UserId}", userId);
try
{
var sessions = await _context.UserSessions
.AsNoTracking()
.Where(s => s.UserId == userId && !s.IsRevoked)
.ToListAsync();
return sessions;
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to fetch user sessions for user {UserId}", userId);
return Result<List<UserSession>>.Failure(ex);
}
}
}
@@ -0,0 +1,80 @@
using Govor.Application.Authentication.JWT;
using Govor.Domain;
using Govor.Domain.Common;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace Govor.Application.Users.UserSessions;
public class UserSessionRefresher : IUserSessionRefresher
{
private readonly ILogger<UserSessionRefresher> _logger;
private readonly JwtRefreshOption _options;
private readonly IJwtTokenHasher _jwtTokenHasher;
private readonly IJwtService _jwtService;
private readonly GovorDbContext _context;
public UserSessionRefresher(
ILogger<UserSessionRefresher> logger,
IOptions<JwtRefreshOption> options,
IJwtTokenHasher jwtTokenHasher,
IJwtService jwtService,
GovorDbContext context)
{
_logger = logger;
_options = options.Value;
_jwtTokenHasher = jwtTokenHasher;
_jwtService = jwtService;
_context = context;
}
public async Task<Result<RefreshResult>> RefreshTokenAsync(string refreshToken)
{
if (string.IsNullOrWhiteSpace(refreshToken))
{
return Result<RefreshResult>.Failure(new Error("Auth.EmptyToken", "Refresh token cannot be empty."));
}
var hashedToken = _jwtTokenHasher.HashToken(refreshToken);
try
{
var session = await _context.UserSessions
.AsNoTracking()
.Include(userSession => userSession.User)
.FirstOrDefaultAsync(s => s.RefreshTokenHash == hashedToken);
if (session is null)
{
_logger.LogWarning("Refresh token session not found for hashed token");
return Result<RefreshResult>.Failure(new Error("Auth.InvalidToken", "Invalid refresh token."));
}
if (session.IsRevoked || session.ExpiresAt <= DateTime.UtcNow)
{
_logger.LogWarning("Attempted to refresh an expired or revoked session: {SessionId}", session.Id);
return Result<RefreshResult>.Failure(new Error("Auth.InvalidToken", "Refresh token is invalid or expired."));
}
var newAccessToken = await _jwtService.GenerateAccessTokenAsync(session.User, session.Id);
var newRefreshToken = await _jwtService.GenerateRefreshTokenAsync(session.User);
var newRefreshTokenHash = _jwtTokenHasher.HashToken(newRefreshToken);
session.RefreshTokenHash = newRefreshTokenHash;
session.CreatedAt = DateTime.UtcNow;
session.ExpiresAt = DateTime.UtcNow.AddDays(_options.RefreshTokenLifetimeDays);
await _context.SaveChangesAsync();
_logger.LogInformation("Successfully refreshed session {SessionId} for user {UserId}", session.Id, session.UserId);
return new RefreshResult(newRefreshToken, newAccessToken);
}
catch (Exception ex)
{
_logger.LogError(ex, "Database error occurred during token refresh execution");
return Result<RefreshResult>.Failure(ex);
}
}
}
@@ -0,0 +1,85 @@
using Govor.Application.PushNotifications;
using Govor.Domain;
using Govor.Domain.Common;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
namespace Govor.Application.Users.UserSessions;
public class UserSessionRevoker : IUserSessionRevoker
{
private readonly GovorDbContext _context;
private readonly IPushTokenService _tokenService;
private readonly ILogger<UserSessionRevoker> _logger;
public UserSessionRevoker(
GovorDbContext context,
IPushTokenService tokenService,
ILogger<UserSessionRevoker> logger)
{
_tokenService = tokenService;
_context = context;
_logger = logger;
}
public async Task<Result> CloseSessionByIdAsync(Guid sessionId, Guid userId)
{
_logger.LogInformation("Attempting to close session {SessionId} for user {UserId}", sessionId, userId);
try
{
var session = await _context.UserSessions
.FirstOrDefaultAsync(s => s.Id == sessionId && s.UserId == userId && !s.IsRevoked);
if (session is null)
{
_logger.LogWarning("Active session {SessionId} not found or doesn't belong to user {UserId}", sessionId, userId);
return Result.Failure(new Error(
"UserSession.NotFoundOrUnauthorized",
$"Active session {sessionId} for user {userId} was not found."));
}
session.IsRevoked = true;
await _context.SaveChangesAsync();
await _tokenService.DeactivateTokenBySessionAsync(sessionId);
_logger.LogInformation("Successfully revoked session {SessionId}", sessionId);
return Result.Success();
}
catch (Exception ex)
{
_logger.LogError(ex, "Error occurred while closing session {SessionId}", sessionId);
return Result.Failure(ex);
}
}
public async Task<Result> CloseAllSessionsAsync(Guid userId)
{
_logger.LogInformation("Attempting to close all active sessions for user {UserId}", userId);
try
{
var updatedRowsCount = await _context.UserSessions
.Where(s => s.UserId == userId && !s.IsRevoked)
.ExecuteUpdateAsync(setters => setters.SetProperty(s => s.IsRevoked, true));
if (updatedRowsCount == 0)
{
_logger.LogInformation("User {UserId} had no active sessions to close", userId);
return Result.Success();
}
await _tokenService.DeactivateAllTokensByUserIdAsync(userId);
_logger.LogInformation("Successfully revoked all {Count} active sessions for user {UserId}", updatedRowsCount, userId);
return Result.Success();
}
catch (Exception ex)
{
_logger.LogError(ex, "Error occurred while closing all sessions for user {UserId}", userId);
return Result.Failure(ex);
}
}
}