using Govor.Application.Interfaces.UserSession; using Govor.Core.Repositories.UserSessionsRepository; using Govor.Data.Repositories.Exceptions; using Microsoft.Extensions.Logging; namespace Govor.Application.Services.UserSessions; public class UserSessionReader : IUserSessionReader { private readonly IUserSessionsRepository _repository; private readonly ILogger _logger; public UserSessionReader(IUserSessionsRepository repository, ILogger logger) { _repository = repository; _logger = logger; } public async Task> GetAllSessionsAsync(Guid userId) { try { _logger.LogInformation($"Getting all sessions for user {userId}"); var sessions = await _repository.GetByUserIdAsync(userId); return sessions.Where(f => !f.IsRevoked).ToList() ?? []; } catch (NotFoundByKeyException ex) { _logger.LogWarning("The user has no sessions."); return []; } } }