using MediatR; using Modules.User.Application.Gateways; namespace Modules.User.Application.Commands.Session; public class DeleteSessionCommand : IRequest { public Guid AccountId { get; init; } public Guid SessionId { get; init; } } public class DeleteSessionCommandHandler(IUserRepository userRepository, IUnitOfWork unitOfWork) : IRequestHandler { public async Task Handle(DeleteSessionCommand request, CancellationToken cancellationToken) { var user = await userRepository.GetByAccountIdAsync(request.AccountId, cancellationToken); if (user == null) return false; //TODO: if (user == null) throw new UserNotFoundException(); //"User not found" var success = user.DeleteSession(request.SessionId); if (!success) return false; //TODO: if (!success) throw new Exception("Session not found"); await userRepository.SaveAsync(user, cancellationToken); await unitOfWork.SaveChangesAsync(cancellationToken); return true; } }