mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-21 14:04:12 +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 System.Threading.Tasks;
|
||||||
using BTCPayServer.Client;
|
using BTCPayServer.Client;
|
||||||
using BTCPayServer.Client.Models;
|
using BTCPayServer.Client.Models;
|
||||||
|
using BTCPayServer.Controllers.Logic;
|
||||||
using BTCPayServer.Data;
|
using BTCPayServer.Data;
|
||||||
using BTCPayServer.Events;
|
using BTCPayServer.Events;
|
||||||
using BTCPayServer.Filters;
|
using BTCPayServer.Filters;
|
||||||
|
@ -598,17 +599,11 @@ namespace BTCPayServer.Controllers
|
||||||
return Ok("{}");
|
return Ok("{}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public class InvoicePreference
|
|
||||||
{
|
|
||||||
public int? TimezoneOffset { get; set; }
|
|
||||||
public string SearchTerm { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("invoices")]
|
[Route("invoices")]
|
||||||
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie)]
|
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie)]
|
||||||
[BitpayAPIConstraint(false)]
|
[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
|
// 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
|
// 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;
|
null;
|
||||||
if (searchTerm is 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;
|
searchTerm = preferences.SearchTerm;
|
||||||
timezoneOffset = timezoneOffset is int v ? v : preferences.TimezoneOffset;
|
timezoneOffset = preferences.TimezoneOffset ?? 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var preferences = new InvoicePreference();
|
this.Response.Cookies.Append(ListInvoicesPreference.KEY,
|
||||||
preferences.SearchTerm = searchTerm;
|
JsonConvert.SerializeObject(new ListInvoicesPreference(searchTerm, timezoneOffset)));
|
||||||
preferences.TimezoneOffset = timezoneOffset;
|
|
||||||
this.Response.Cookies.Append("ListInvoicePreferences", JsonConvert.SerializeObject(preferences));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var fs = new SearchString(searchTerm);
|
var fs = new SearchString(searchTerm);
|
||||||
var storeIds = fs.GetFilterArray("storeid") != null ? fs.GetFilterArray("storeid") : new List<string>().ToArray();
|
var storeIds = fs.GetFilterArray("storeid") != null ? fs.GetFilterArray("storeid") : new List<string>().ToArray();
|
||||||
|
|
||||||
|
@ -643,7 +637,7 @@ namespace BTCPayServer.Controllers
|
||||||
StoreIds = storeIds,
|
StoreIds = storeIds,
|
||||||
TimezoneOffset = timezoneOffset
|
TimezoneOffset = timezoneOffset
|
||||||
};
|
};
|
||||||
InvoiceQuery invoiceQuery = GetInvoiceQuery(searchTerm, timezoneOffset ?? 0);
|
InvoiceQuery invoiceQuery = GetInvoiceQuery(searchTerm, timezoneOffset);
|
||||||
var counting = _InvoiceRepository.GetInvoicesTotal(invoiceQuery);
|
var counting = _InvoiceRepository.GetInvoicesTotal(invoiceQuery);
|
||||||
invoiceQuery.Count = count;
|
invoiceQuery.Count = count;
|
||||||
invoiceQuery.Skip = skip;
|
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