Created SessionController and UserSessionReader

+ tests for UserSessionReader
This commit is contained in:
Artemy
2025-07-24 17:03:51 +07:00
parent 19f1ccdfd5
commit 15f9370dbe
7 changed files with 224 additions and 1 deletions
@@ -0,0 +1,34 @@
using Govor.Application.Interfaces.UserSession;
using Govor.Core.Models;
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<UserSessionReader> _logger;
public UserSessionReader(IUserSessionsRepository repository, ILogger<UserSessionReader> logger)
{
_repository = repository;
_logger = logger;
}
public async Task<List<UserSession>> GetAllSessionsAsync(Guid userId)
{
try
{
_logger.LogInformation($"Getting all sessions for user {userId}");
var sessions = await _repository.GetByUserIdAsync(userId);
return sessions;
}
catch (NotFoundByKeyException<Guid> ex)
{
_logger.LogWarning("The user has no active sessions.");
return [];
}
}
}