@@ -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 {
0 commit comments