mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 11:44:56 +00:00
Created SessionController and UserSessionReader
+ tests for UserSessionReader
This commit is contained in:
@@ -3,6 +3,6 @@ namespace Govor.Application.Interfaces.UserSession;
|
||||
|
||||
public interface IUserSessionRevoker
|
||||
{
|
||||
Task CloseSessionByRefreshTokenAsync(string refreshToken);
|
||||
Task CloseSessionByIdAsync(Guid sessionId, Guid userId);
|
||||
Task CloseAllSessionsAsync(Guid userId);
|
||||
}
|
||||
|
||||
@@ -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 [];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user