btcpayserver/BTCPayServer/Controllers/UIAppsController.Dashboard.cs
Dennis Reimann 01ab21e4c0 Dashboard: Fix app tiles
I broke this with #3987.
2022-08-23 12:07:18 +02:00

66 lines
2.3 KiB
C#

using System;
using System.Threading.Tasks;
using BTCPayServer.Abstractions.Constants;
using BTCPayServer.Client;
using BTCPayServer.Components.AppSales;
using BTCPayServer.Components.AppTopItems;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace BTCPayServer.Controllers
{
public partial class UIAppsController
{
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)]
[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 });
}
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)]
[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 });
}
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)]
[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);
}
}
}