Skip to content

Commit 4e2f211

Browse files
committed
[GEN-1863] Wallets pagination + filtering
Add GetPaginatedAsync method to WalletRepository and IWalletRepository interface with comprehensive filtering options including name, status, wallet type, date range, and various boolean filters. Update Wallets page UI to support paginated display with filter controls for improved wallet management and navigation. stack-info: PR: #484, branch: Jossec101/stack/17
1 parent 5242c9a commit 4e2f211

3 files changed

Lines changed: 259 additions & 34 deletions

File tree

src/Data/Repositories/Interfaces/IWalletRepository.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ public interface IWalletRepository
2727
Task<Wallet?> GetById(int id);
2828

2929
Task<List<Wallet>> GetAll();
30+
31+
Task<(List<Wallet> wallets, int totalCount)> GetPaginatedAsync(
32+
int pageNumber,
33+
int pageSize,
34+
string? nameFilter = null,
35+
string? statusFilter = null,
36+
bool archivedFilter = false,
37+
bool compromisedFilter = false,
38+
bool hotWalletFilter = false,
39+
bool coldWalletFilter = false,
40+
bool finalisedFilter = false,
41+
DateTimeOffset? fromDate = null,
42+
DateTimeOffset? toDate = null);
3043

3144
Task<List<Wallet>> GetAvailableByType(WALLET_TYPE type);
3245

src/Data/Repositories/WalletRepository.cs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,90 @@ public async Task<List<Wallet>> GetAll()
7070
return await applicationDbContext.Wallets.Include(x => x.InternalWallet).Include(x => x.Keys).ToListAsync();
7171
}
7272

73+
public async Task<(List<Wallet> wallets, int totalCount)> GetPaginatedAsync(
74+
int pageNumber,
75+
int pageSize,
76+
string? nameFilter = null,
77+
string? statusFilter = null,
78+
bool archivedFilter = false,
79+
bool compromisedFilter = false,
80+
bool hotWalletFilter = false,
81+
bool coldWalletFilter = false,
82+
bool finalisedFilter = false,
83+
DateTimeOffset? fromDate = null,
84+
DateTimeOffset? toDate = null)
85+
{
86+
await using var applicationDbContext = await _dbContextFactory.CreateDbContextAsync();
87+
88+
var query = applicationDbContext.Wallets
89+
.Include(x => x.InternalWallet)
90+
.Include(x => x.Keys)
91+
.AsQueryable();
92+
93+
if (!string.IsNullOrWhiteSpace(nameFilter))
94+
{
95+
query = query.Where(w => w.Name.Contains(nameFilter));
96+
}
97+
98+
switch (statusFilter)
99+
{
100+
case "Finalised":
101+
query = query.Where(w => w.IsFinalised);
102+
break;
103+
case "Not Finalised":
104+
query = query.Where(w => !w.IsFinalised);
105+
break;
106+
case "Archived":
107+
query = query.Where(w => w.IsArchived);
108+
break;
109+
case "Not Archived":
110+
query = query.Where(w => !w.IsArchived);
111+
break;
112+
}
113+
114+
if (fromDate.HasValue)
115+
{
116+
query = query.Where(w => w.CreationDatetime >= fromDate.Value);
117+
}
118+
119+
if (toDate.HasValue)
120+
{
121+
query = query.Where(w => w.CreationDatetime <= toDate.Value);
122+
}
123+
124+
if (!archivedFilter && statusFilter != "Archived")
125+
{
126+
query = query.Where(w => !w.IsArchived);
127+
}
128+
129+
if (!compromisedFilter)
130+
{
131+
query = query.Where(w => !w.IsCompromised);
132+
}
133+
134+
var anyPropertyFilter = archivedFilter || compromisedFilter || hotWalletFilter || coldWalletFilter || finalisedFilter;
135+
if (anyPropertyFilter)
136+
{
137+
query = query.Where(w =>
138+
(archivedFilter && w.IsArchived) ||
139+
(compromisedFilter && w.IsCompromised) ||
140+
(hotWalletFilter && w.IsHotWallet) ||
141+
(coldWalletFilter && !w.IsHotWallet) ||
142+
(finalisedFilter && w.IsFinalised));
143+
}
144+
145+
query = query.OrderByDescending(w => w.CreationDatetime);
146+
147+
var totalCount = await query.CountAsync();
148+
149+
var wallets = await query
150+
.Skip((pageNumber - 1) * pageSize)
151+
.Take(pageSize)
152+
.ToListAsync();
153+
154+
return (wallets, totalCount);
155+
}
156+
73157
public async Task<List<Wallet>> GetAvailableByType(WALLET_TYPE type)
74158
{
75159
await using var applicationDbContext = await _dbContextFactory.CreateDbContextAsync();

0 commit comments

Comments
 (0)