-
Notifications
You must be signed in to change notification settings - Fork 312
Added pagination and search to History #2702
Changes from all commits
b84a362
bceeb2c
f8718b5
6f688f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -375,7 +375,8 @@ public IActionResult GetHistory([FromQuery] WalletHistoryRequest request) | |
{ | ||
var transactionItems = new List<TransactionItemModel>(); | ||
|
||
List<FlatHistory> items = accountHistory.History.OrderByDescending(o => o.Transaction.CreationTime).Take(200).ToList(); | ||
List<FlatHistory> items = accountHistory.History.OrderByDescending(o => o.Transaction.CreationTime).ToList(); | ||
items = string.IsNullOrEmpty(request.SearchQuery) ? items.Take(200).ToList() : items; | ||
|
||
// Represents a sublist containing only the transactions that have already been spent. | ||
List<FlatHistory> spendingDetails = items.Where(t => t.Transaction.SpendingDetails != null).ToList(); | ||
|
@@ -497,9 +498,16 @@ public IActionResult GetHistory([FromQuery] WalletHistoryRequest request) | |
} | ||
} | ||
|
||
// Sort and filter the history items. | ||
List<TransactionItemModel> itemsToInclude = transactionItems.OrderByDescending(t => t.Timestamp) | ||
.Where(x => string.IsNullOrEmpty(request.SearchQuery) || (x.Id.ToString() == request.SearchQuery || x.ToAddress == request.SearchQuery || x.Payments.Any(p => p.DestinationAddress == request.SearchQuery))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if SearchQuery is null or empty? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, that's the beauty of this statement! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so you want to take all items if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah yeah thats what want so you apply the rest of the linq qeruey |
||
.Skip(request.Skip ?? 0) | ||
.Take(request.Take ?? transactionItems.Count) | ||
.ToList(); | ||
|
||
model.AccountsHistoryModel.Add(new AccountHistoryModel | ||
{ | ||
TransactionsHistory = transactionItems.OrderByDescending(t => t.Timestamp).ToList(), | ||
TransactionsHistory = itemsToInclude, | ||
Name = accountHistory.Account.Name, | ||
CoinType = this.coinType, | ||
HdPath = accountHistory.Account.HdPath | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,6 +107,13 @@ public class WalletHistoryRequest : RequestModel | |
public string WalletName { get; set; } | ||
|
||
public string AccountName { get; set; } | ||
|
||
public int? Skip { get; set; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cant you just default this to 0 then you don't have to do a coalesce? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For Skip that wouldn't be a problem, but then how do I interpret |
||
|
||
public int? Take { get; set; } | ||
|
||
[JsonProperty(PropertyName = "q")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would call this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. q is kind of an API convention for search queries. I think it's ok. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the value included in the URL? |
||
public string SearchQuery { get; set; } | ||
} | ||
|
||
public class WalletBalanceRequest : RequestModel | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bokobza a bit more readable:
Also, no reason to
ToList()
unless the intention is to take a copy.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is as readable as
I need ToList, the type I get from
OrderByDescending
isIOrderedEnumerable<FlatHistory>
.