btcpayserver/BTCPayServer/Controllers/UIAppsController.Dashboard.cs
d11n 657423207b
Async dashboard (#3916)
* Dashboard: Load Lightning balance async, display default currency

* Simplify approach, improve views and scripts

* Async tiles


Async tiles

* Add period for app sales

* Fix missing keypad view sales

* Fix after rebase

* Fix awaited call

* Fix build

Co-authored-by: Nicolas Dorier <nicolas.dorier@gmail.com>
2022-07-06 12:40:16 +09:00

60 lines
1.8 KiB
C#

using System;
using System.Threading.Tasks;
using BTCPayServer.Components.AppSales;
using BTCPayServer.Components.AppTopItems;
using Microsoft.AspNetCore.Mvc;
namespace BTCPayServer.Controllers
{
public partial class UIAppsController
{
[HttpGet("{appId}/dashboard/app-top-items")]
public IActionResult AppTopItems(string appId)
{
var app = HttpContext.GetAppData();
if (app == null)
return NotFound();
app.StoreData = GetCurrentStore();
var vm = new AppTopItemsViewModel { App = app };
return ViewComponent("AppTopItems", new { vm });
}
[HttpGet("{appId}/dashboard/app-sales")]
public IActionResult AppSales(string appId)
{
var app = HttpContext.GetAppData();
if (app == null)
return NotFound();
app.StoreData = GetCurrentStore();
var vm = new AppSalesViewModel { App = app };
return ViewComponent("AppSales", new { vm });
}
[HttpGet("{appId}/dashboard/app-sales/{period}")]
public async Task<IActionResult> AppSales(string appId, AppSalesPeriod period)
{
var app = HttpContext.GetAppData();
if (app == null)
return NotFound();
app.StoreData = GetCurrentStore();
var days = period switch
{
AppSalesPeriod.Week => 7,
AppSalesPeriod.Month => 30,
_ => throw new ArgumentException($"AppSalesPeriod {period} does not exist.")
};
var stats = await _appService.GetSalesStats(app, days);
return stats == null
? NotFound()
: Json(stats);
}
}
}