-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add purchase datagrid and fetch purchases from db (#44)
* Add purchase datagrid and fetch purchases from db * Revert appsettings * Oops i reverted the wrong appsettings * PR comments * Update apihost * Remove cosole writeline
- Loading branch information
1 parent
36ac002
commit 181b0bb
Showing
11 changed files
with
464 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
@namespace Components | ||
@using System.ComponentModel.DataAnnotations | ||
@using MudExtensions | ||
@using Shifty.App.Services | ||
@using Shifty.Api.Generated.AnalogCoreV1 | ||
@using Shifty.Api.Generated.AnalogCoreV2 | ||
@using Shared | ||
@using LanguageExt.UnsafeValueAccess | ||
@using Components | ||
@using Shifty.App.DomainModels | ||
@using System.Collections.ObjectModel | ||
@inject IPurchaseService PurchaseService | ||
@inject ISnackbar Snackbar | ||
|
||
<MudPaper Elevation="15" Style="border-radius: 5px; width:fit-content; min-width: 500px; margin:2rem auto"> | ||
@if(_purchasesFetched) | ||
{ | ||
<MudIconButton Icon="@Icons.Material.Filled.ArrowBack" Color="Color.Primary" OnClick="@(() => _purchasesFetched = false)" /> | ||
<MudDataGrid | ||
T="Purchase" | ||
Items="@_purchases" | ||
ReadOnly="true" | ||
FixedHeader="true" | ||
Height="calc(100vh - 250px)" | ||
SortMode="MudBlazor.SortMode.None" | ||
Style="width: 70vw;padding: 1rem" | ||
> | ||
<Columns> | ||
<PropertyColumn Property="x => x.Id" Title="Id" /> | ||
<PropertyColumn Property="x => x.DateCreated" Title="Date" /> | ||
<PropertyColumn Property="x => x.ProductName" Title="Name" /> | ||
<PropertyColumn Property="x => x.NumberOfTickets" Title="Tickets" /> | ||
<PropertyColumn Property="x => x.Price" Title="Price" /> | ||
<PropertyColumn Property="x => x.PurchaseStatus" Title="Status" > | ||
<CellTemplate> | ||
@{ | ||
if(@context.Item.PurchaseStatus == PurchaseStatus.Completed) | ||
{ | ||
<MudButton Size="@Size.Small" Color="Color.Primary" Variant="Variant.Filled" OnClick="@(() => RefundPurchase(context.Item))"> | ||
Refund | ||
</MudButton> | ||
} | ||
else | ||
{ | ||
<MudText>@context.Item.PurchaseStatus</MudText> | ||
} | ||
} | ||
</CellTemplate> | ||
</PropertyColumn> | ||
</Columns> | ||
</MudDataGrid> | ||
} | ||
else | ||
{ | ||
<MudContainer Style="padding: 2rem; display: flex; flex-direction: column; justify-content: center;"> | ||
<MudText Style="padding: 0.5rem;">Find purchases for user</MudText> | ||
<MudTextField Immediate="true" OnKeyDown="OnKeyDown" @bind-Value="UserId" Label="User ID" Variant="Variant.Outlined" Adornment="Adornment.End" AdornmentIcon="@Icons.Material.Filled.Search" AdornmentColor="Color.Secondary"></MudTextField> | ||
</MudContainer> | ||
} | ||
</MudPaper> | ||
|
||
@code { | ||
private int UserId; | ||
private bool _loading = true; | ||
Check warning on line 64 in Shifty.App/Components/Refunds.razor GitHub Actions / dev-deploy / Build codebase / Build webapp / Build and test Webapp
Check warning on line 64 in Shifty.App/Components/Refunds.razor GitHub Actions / dev-deploy / Build codebase / Build webapp / Build and test Webapp
Check warning on line 64 in Shifty.App/Components/Refunds.razor GitHub Actions / dev-deploy / Build codebase / Build webapp / Build and test Webapp
Check warning on line 64 in Shifty.App/Components/Refunds.razor GitHub Actions / prd-deploy / Build codebase / Build webapp / Build and test Webapp
Check warning on line 64 in Shifty.App/Components/Refunds.razor GitHub Actions / prd-deploy / Build codebase / Build webapp / Build and test Webapp
|
||
private bool _purchasesFetched = false; | ||
private List<Purchase> _purchases; | ||
|
||
private async Task GetPurchases() | ||
{ | ||
var result = await PurchaseService.GetPurchases(UserId); | ||
result.Match( | ||
purchases => | ||
{ | ||
_purchases = purchases.OrderByDescending(x => x.DateCreated).ToList(); | ||
_purchasesFetched = true; | ||
}, | ||
error => Snackbar.Add(error.Message, Severity.Error) | ||
); | ||
_loading = false; | ||
} | ||
|
||
async void OnKeyDown(KeyboardEventArgs args) | ||
{ | ||
if (args.Key=="Enter") | ||
{ | ||
_loading = true; | ||
await GetPurchases(); | ||
StateHasChanged(); | ||
} | ||
|
||
} | ||
|
||
private async Task RefundPurchase(Purchase purchase) | ||
{ | ||
var result = await PurchaseService.RefundPurchase(purchase.Id); | ||
result.Match( | ||
_ => Snackbar.Add("Purchase refunded", Severity.Success), | ||
error => Snackbar.Add(error.Message, Severity.Error) | ||
); | ||
_loading = true; | ||
await GetPurchases(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using Microsoft.VisualBasic; | ||
using Shifty.Api.Generated.AnalogCoreV1; | ||
using Shifty.Api.Generated.AnalogCoreV2; | ||
|
||
namespace Shifty.App.DomainModels | ||
{ | ||
public record Purchase { | ||
public int Id { get; init; } | ||
public int NumberOfTickets { get; set; } | ||
public int Price { get; set; } | ||
public string ProductName { get; set; } | ||
public int ProductId { get; set; } | ||
public PurchaseStatus PurchaseStatus { get; set; } | ||
|
||
public DateTimeOffset DateCreated { get; set; } | ||
|
||
public static Purchase FromDto(SimplePurchaseResponse dto) | ||
{ | ||
return new Purchase() | ||
{ | ||
Id = dto.Id, | ||
DateCreated = dto.DateCreated, | ||
NumberOfTickets = dto.NumberOfTickets, | ||
Price = dto.TotalAmount, | ||
PurchaseStatus = dto.PurchaseStatus, | ||
ProductName = dto.ProductName, | ||
ProductId = dto.ProductId | ||
}; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
@page "/Refunds" | ||
@using Components | ||
@inject NavigationManager NavManager | ||
|
||
@if (_user is not null && _user.IsInRole("Board")) | ||
{ | ||
<Refunds /> | ||
} | ||
|
||
@code { | ||
[CascadingParameter] public Task<AuthenticationState> AuthTask { get; set; } | ||
private System.Security.Claims.ClaimsPrincipal _user; | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
var authState = await AuthTask; | ||
_user = authState.User; | ||
|
||
if (_user is null || !_user.IsInRole("Board")) | ||
{ | ||
NavManager.NavigateTo("/"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.