mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 06:24:24 +01:00
Refactoring ListInvoicePreferences
This commit is contained in:
@@ -8,6 +8,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BTCPayServer.Client;
|
||||
using BTCPayServer.Client.Models;
|
||||
using BTCPayServer.Controllers.Logic;
|
||||
using BTCPayServer.Data;
|
||||
using BTCPayServer.Events;
|
||||
using BTCPayServer.Filters;
|
||||
@@ -598,17 +599,11 @@ namespace BTCPayServer.Controllers
|
||||
return Ok("{}");
|
||||
}
|
||||
|
||||
public class InvoicePreference
|
||||
{
|
||||
public int? TimezoneOffset { get; set; }
|
||||
public string SearchTerm { get; set; }
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("invoices")]
|
||||
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie)]
|
||||
[BitpayAPIConstraint(false)]
|
||||
public async Task<IActionResult> ListInvoices(string searchTerm = null, int skip = 0, int count = 50, int? timezoneOffset = null)
|
||||
public async Task<IActionResult> ListInvoices(string searchTerm = null, int skip = 0, int count = 50, int timezoneOffset = 0)
|
||||
{
|
||||
// If the user enter an empty searchTerm, then the variable will be null and not empty string
|
||||
// but we want searchTerm to be null only if the user is browsing the page via some link
|
||||
@@ -618,20 +613,19 @@ namespace BTCPayServer.Controllers
|
||||
null;
|
||||
if (searchTerm is null)
|
||||
{
|
||||
if (this.Request.Cookies.TryGetValue("ListInvoicePreferences", out var str))
|
||||
if (this.Request.Cookies.TryGetValue(ListInvoicesPreference.KEY, out var str))
|
||||
{
|
||||
var preferences = JsonConvert.DeserializeObject<InvoicePreference>(str);
|
||||
var preferences = JsonConvert.DeserializeObject<ListInvoicesPreference>(str);
|
||||
searchTerm = preferences.SearchTerm;
|
||||
timezoneOffset = timezoneOffset is int v ? v : preferences.TimezoneOffset;
|
||||
timezoneOffset = preferences.TimezoneOffset ?? 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var preferences = new InvoicePreference();
|
||||
preferences.SearchTerm = searchTerm;
|
||||
preferences.TimezoneOffset = timezoneOffset;
|
||||
this.Response.Cookies.Append("ListInvoicePreferences", JsonConvert.SerializeObject(preferences));
|
||||
this.Response.Cookies.Append(ListInvoicesPreference.KEY,
|
||||
JsonConvert.SerializeObject(new ListInvoicesPreference(searchTerm, timezoneOffset)));
|
||||
}
|
||||
|
||||
var fs = new SearchString(searchTerm);
|
||||
var storeIds = fs.GetFilterArray("storeid") != null ? fs.GetFilterArray("storeid") : new List<string>().ToArray();
|
||||
|
||||
@@ -643,7 +637,7 @@ namespace BTCPayServer.Controllers
|
||||
StoreIds = storeIds,
|
||||
TimezoneOffset = timezoneOffset
|
||||
};
|
||||
InvoiceQuery invoiceQuery = GetInvoiceQuery(searchTerm, timezoneOffset ?? 0);
|
||||
InvoiceQuery invoiceQuery = GetInvoiceQuery(searchTerm, timezoneOffset);
|
||||
var counting = _InvoiceRepository.GetInvoicesTotal(invoiceQuery);
|
||||
invoiceQuery.Count = count;
|
||||
invoiceQuery.Skip = skip;
|
||||
|
||||
Reference in New Issue
Block a user