Skip to content

Commit 7582b3e

Browse files
committed
[GEN-1863] Pagination channels + filters
- Add GetPaginatedAsync method to ChannelRepository with comprehensive filtering options (status, nodes, wallet, date range) - Implement IChannelRepository interface with pagination support and detailed XML documentation - Create ChannelManagement component with filtering UI including status, node, and date filters - Add pagination controls and channel display with creation date, status, and capacity information stack-info: PR: #480, branch: Jossec101/stack/13
1 parent 93e9056 commit 7582b3e

3 files changed

Lines changed: 281 additions & 122 deletions

File tree

src/Data/Repositories/ChannelRepository.cs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,82 @@ public async Task<List<Channel>> GetAllManagedByUserNodes(string loggedUserId)
218218
return channels;
219219
}
220220

221+
public async Task<(List<Channel>, int)> GetPaginatedAsync(
222+
string loggedUserId,
223+
int pageNumber,
224+
int pageSize,
225+
int? statusFilter = null,
226+
int? sourceNodeIdFilter = null,
227+
int? destinationNodeIdFilter = null,
228+
int? walletIdFilter = null,
229+
DateTimeOffset? fromDate = null,
230+
DateTimeOffset? toDate = null)
231+
{
232+
if (string.IsNullOrWhiteSpace(loggedUserId))
233+
throw new ArgumentException("Value cannot be null or whitespace.", nameof(loggedUserId));
234+
235+
await using var applicationDbContext = await _dbContextFactory.CreateDbContextAsync();
236+
237+
var query = applicationDbContext.Channels
238+
.Include(channel => channel.ChannelOperationRequests).ThenInclude(request => request.SourceNode).ThenInclude(x => x.Users)
239+
.Include(channel => channel.ChannelOperationRequests).ThenInclude(request => request.DestNode).ThenInclude(x => x.Users)
240+
.Include(channel => channel.ChannelOperationRequests).ThenInclude(request => request.Wallet)
241+
.Include(channel => channel.ChannelOperationRequests).ThenInclude(request => request.ChannelOperationRequestPsbts)
242+
.Include(x => x.SourceNode)
243+
.Include(x => x.DestinationNode)
244+
.Include(x => x.LiquidityRules)
245+
.ThenInclude(x => x.Node)
246+
.Include(x => x.LiquidityRules)
247+
.ThenInclude(x => x.SwapWallet)
248+
.Include(x => x.LiquidityRules)
249+
.ThenInclude(x => x.ReverseSwapWallet)
250+
.AsSplitQuery()
251+
.Where(x => x.SourceNode.Users.Select(user => user.Id).Contains(loggedUserId) ||
252+
x.DestinationNode.Users.Select(user => user.Id).Contains(loggedUserId));
253+
254+
// Apply filters
255+
if (statusFilter.HasValue)
256+
{
257+
var status = (Channel.ChannelStatus)statusFilter.Value;
258+
query = query.Where(x => x.Status == status);
259+
}
260+
261+
if (sourceNodeIdFilter.HasValue)
262+
{
263+
query = query.Where(x => x.SourceNodeId == sourceNodeIdFilter.Value);
264+
}
265+
266+
if (destinationNodeIdFilter.HasValue)
267+
{
268+
query = query.Where(x => x.DestinationNodeId == destinationNodeIdFilter.Value);
269+
}
270+
271+
if (walletIdFilter.HasValue)
272+
{
273+
query = query.Where(x => x.ChannelOperationRequests.Any(r => r.WalletId == walletIdFilter.Value));
274+
}
275+
276+
if (fromDate.HasValue)
277+
{
278+
query = query.Where(x => x.CreationDatetime >= fromDate.Value);
279+
}
280+
281+
if (toDate.HasValue)
282+
{
283+
query = query.Where(x => x.CreationDatetime <= toDate.Value);
284+
}
285+
286+
var totalCount = await query.CountAsync();
287+
288+
var channels = await query
289+
.OrderByDescending(x => x.CreationDatetime)
290+
.Skip((pageNumber - 1) * pageSize)
291+
.Take(pageSize)
292+
.ToListAsync();
293+
294+
return (channels, totalCount);
295+
}
296+
221297

222298
public async Task<(bool, string?)> MarkAsClosed(Channel channel)
223299
{

src/Data/Repositories/Interfaces/IChannelRepository.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,18 @@ public interface IChannelRepository
5454
/// <param name="loggedUserId"></param>
5555
/// <returns></returns>
5656
Task<List<Channel>> GetAllManagedByUserNodes(string loggedUserId);
57+
58+
/// <summary>
59+
/// Retrieves paginated channels managed by user with filters
60+
/// </summary>
61+
Task<(List<Channel>, int)> GetPaginatedAsync(
62+
string loggedUserId,
63+
int pageNumber,
64+
int pageSize,
65+
int? statusFilter = null,
66+
int? sourceNodeIdFilter = null,
67+
int? destinationNodeIdFilter = null,
68+
int? walletIdFilter = null,
69+
DateTimeOffset? fromDate = null,
70+
DateTimeOffset? toDate = null);
5771
}

0 commit comments

Comments
 (0)