Add payments page with transaction history

This commit is contained in:
Baumgartner Marcel 2023-10-23 15:04:57 +02:00
parent e062df4eb6
commit ff9bcc6433
3 changed files with 79 additions and 2 deletions

View file

@ -1,4 +1,6 @@
using Moonlight.App.Database.Entities;
using Microsoft.EntityFrameworkCore;
using Moonlight.App.Database.Entities;
using Moonlight.App.Database.Entities.Store;
using Moonlight.App.Exceptions;
using Moonlight.App.Helpers;
using Moonlight.App.Models.Abstractions;
@ -23,6 +25,7 @@ public class IdentityService
public bool IsSignedIn => CurrentUserNullable != null;
public FlagStorage Flags { get; private set; } = new("");
public PermissionStorage Permissions { get; private set; } = new(-1);
public Transaction[] Transactions => GetTransactions().Result; // TODO: make more efficient
public EventHandler OnAuthenticationStateChanged { get; set; }
public IdentityService(Repository<User> userRepository,
@ -32,6 +35,20 @@ public class IdentityService
JwtService = jwtService;
}
// Transactions
public Task<Transaction[]> GetTransactions()
{
if (CurrentUserNullable == null)
return Task.FromResult(Array.Empty<Transaction>());
var user = UserRepository
.Get()
.Include(x => x.Transactions)
.First(x => x.Id == CurrentUserNullable.Id);
return Task.FromResult(user.Transactions.ToArray());
}
// Authentication
public async Task Authenticate() // Reauthenticate

View file

@ -1,4 +1,4 @@
<div class="card mb-5 mb-xl-10">
<div class="card mb-5 mb-xl-10">
<div class="card-body pt-0 pb-0">
<ul class="nav nav-stretch nav-line-tabs nav-line-tabs-2x border-transparent fs-5 fw-bold">
<li class="nav-item mt-2">
@ -11,6 +11,11 @@
Security
</a>
</li>
<li class="nav-item mt-2">
<a class="nav-link text-active-primary ms-0 me-10 py-5 @(Index == 2 ? "active" : "")" href="/account/payments">
Payments
</a>
</li>
</ul>
</div>
</div>

View file

@ -0,0 +1,55 @@
@page "/account/payments"
@using Moonlight.App.Services
@using Moonlight.App.Database.Entities.Store
@using BlazorTable
@inject IdentityService IdentityService
@inject ConfigService ConfigService
<AccountNavigation Index="2" />
<div class="card mt-5">
<div class="card-header">
<h3 class="card-title">Transactions</h3>
</div>
<div class="card-body">
<LazyLoader Load="Load">
<Table TableItem="Transaction"
Items="Transactions"
PageSize="50"
TableClass="table table-row-bordered table-row-gray-100 align-middle gs-0 gy-3 fs-6"
TableHeadClass="fw-bold text-muted">
<Column TableItem="Transaction" Title="" Field="@(x => x.Id)" Sortable="false" Filterable="false" Width="10%">
<Template>
@if (context.Price < 0)
{
<i class="bx bx-sm bx-minus text-danger align-middle"></i>
}
else
{
<i class="bx bx-sm bx-plus text-success align-middle"></i>
}
</Template>
</Column>
<Column TableItem="Transaction" Title="" Field="@(x => x.Id)" Sortable="false" Filterable="false">
<Template>
<span>@(ConfigService.Get().Store.Currency) @(Math.Abs(context.Price))</span>
</Template>
</Column>
<Column TableItem="Transaction" Title="" Field="@(x => x.Text)" Sortable="false" Filterable="false"/>
<Pager AlwaysShow="true"/>
</Table>
</LazyLoader>
</div>
</div>
@code
{
private Transaction[] Transactions;
private async Task Load(LazyLoader _)
{
Transactions = await IdentityService.GetTransactions();
}
}