mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-20 13:34:37 +01:00
Refactoring ListInvoicePreferences
This commit is contained in:
parent
b7d66efb20
commit
6bacddc159
2 changed files with 33 additions and 15 deletions
|
@ -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;
|
||||
|
|
24
BTCPayServer/Controllers/Logic/ListInvoicesPreference.cs
Normal file
24
BTCPayServer/Controllers/Logic/ListInvoicesPreference.cs
Normal file
|
@ -0,0 +1,24 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BTCPayServer.Controllers.Logic
|
||||
{
|
||||
public class ListInvoicesPreference
|
||||
{
|
||||
public const string KEY = "ListInvoicePreferences";
|
||||
public ListInvoicesPreference() { }
|
||||
|
||||
public ListInvoicesPreference(string searchTerm, int timezoneOffset)
|
||||
{
|
||||
SearchTerm = searchTerm;
|
||||
if (timezoneOffset != 0)
|
||||
TimezoneOffset = timezoneOffset;
|
||||
}
|
||||
|
||||
public int? TimezoneOffset { get; set; }
|
||||
public string SearchTerm { get; set; }
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue