Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions src/Data/Repositories/ChannelRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,82 @@ public async Task<List<Channel>> GetAllManagedByUserNodes(string loggedUserId)
return channels;
}

public async Task<(List<Channel>, int)> GetPaginatedAsync(
string loggedUserId,
int pageNumber,
int pageSize,
int? statusFilter = null,
int? sourceNodeIdFilter = null,
int? destinationNodeIdFilter = null,
int? walletIdFilter = null,
DateTimeOffset? fromDate = null,
DateTimeOffset? toDate = null)
{
if (string.IsNullOrWhiteSpace(loggedUserId))
throw new ArgumentException("Value cannot be null or whitespace.", nameof(loggedUserId));

await using var applicationDbContext = await _dbContextFactory.CreateDbContextAsync();

var query = applicationDbContext.Channels
.Include(channel => channel.ChannelOperationRequests).ThenInclude(request => request.SourceNode).ThenInclude(x => x.Users)
.Include(channel => channel.ChannelOperationRequests).ThenInclude(request => request.DestNode).ThenInclude(x => x.Users)
.Include(channel => channel.ChannelOperationRequests).ThenInclude(request => request.Wallet)
.Include(channel => channel.ChannelOperationRequests).ThenInclude(request => request.ChannelOperationRequestPsbts)
.Include(x => x.SourceNode)
.Include(x => x.DestinationNode)
.Include(x => x.LiquidityRules)
.ThenInclude(x => x.Node)
.Include(x => x.LiquidityRules)
.ThenInclude(x => x.SwapWallet)
.Include(x => x.LiquidityRules)
.ThenInclude(x => x.ReverseSwapWallet)
.AsSplitQuery()
.Where(x => x.SourceNode.Users.Select(user => user.Id).Contains(loggedUserId) ||
x.DestinationNode.Users.Select(user => user.Id).Contains(loggedUserId));

// Apply filters
if (statusFilter.HasValue)
{
var status = (Channel.ChannelStatus)statusFilter.Value;
query = query.Where(x => x.Status == status);
}

if (sourceNodeIdFilter.HasValue)
{
query = query.Where(x => x.SourceNodeId == sourceNodeIdFilter.Value);
}

if (destinationNodeIdFilter.HasValue)
{
query = query.Where(x => x.DestinationNodeId == destinationNodeIdFilter.Value);
}

if (walletIdFilter.HasValue)
{
query = query.Where(x => x.ChannelOperationRequests.Any(r => r.WalletId == walletIdFilter.Value));
}

if (fromDate.HasValue)
{
query = query.Where(x => x.CreationDatetime >= fromDate.Value);
}

if (toDate.HasValue)
{
query = query.Where(x => x.CreationDatetime <= toDate.Value);
}

var totalCount = await query.CountAsync();

var channels = await query
.OrderByDescending(x => x.CreationDatetime)
.Skip((pageNumber - 1) * pageSize)
.Take(pageSize)
.ToListAsync();

return (channels, totalCount);
}


public async Task<(bool, string?)> MarkAsClosed(Channel channel)
{
Expand Down
14 changes: 14 additions & 0 deletions src/Data/Repositories/Interfaces/IChannelRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,18 @@ public interface IChannelRepository
/// <param name="loggedUserId"></param>
/// <returns></returns>
Task<List<Channel>> GetAllManagedByUserNodes(string loggedUserId);

/// <summary>
/// Retrieves paginated channels managed by user with filters
/// </summary>
Task<(List<Channel>, int)> GetPaginatedAsync(
string loggedUserId,
int pageNumber,
int pageSize,
int? statusFilter = null,
int? sourceNodeIdFilter = null,
int? destinationNodeIdFilter = null,
int? walletIdFilter = null,
DateTimeOffset? fromDate = null,
DateTimeOffset? toDate = null);
}
6 changes: 6 additions & 0 deletions src/Pages/ChannelRequests.razor
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@
TemplatePsbtString="@_templatePSBTString"
SignedPSBT="@_psbt"/>

<CancelOrRejectPopup

Check warning on line 535 in src/Pages/ChannelRequests.razor

View workflow job for this annotation

GitHub Actions / build-and-test

Component 'CancelOrRejectPopup' expects a value for the parameter 'Reason', but a value may not have been provided.
@ref=@_rejectCancelModalRef
Title='@(_selectedStatusActionString + " operation: " + _selectedRequest?.Id)'
Validator="@RejectReasonValidator"
Expand Down Expand Up @@ -695,6 +695,12 @@
{
ToastService.ShowError("Bitcoin price in USD could not be retrieved.");
}
_availableNodes = await NodeRepository.GetAll();
_availableUsers = await ApplicationUserRepository.GetAll();

_statusOptions.AddRange(Enum.GetValues<ChannelOperationRequestStatus>().Cast<ChannelOperationRequestStatus?>());
_requestTypeOptions.AddRange(Enum.GetValues<OperationRequestType>().Cast<OperationRequestType?>());

await FetchRequests();
await LoadData();
}
Expand Down
Loading
Loading