Add authorization and data fetching to sender page
Added an `[Authorize]` attribute with the "Sender" policy to restrict access to the `EnvelopeSenderPage.razor`. Updated the page title to "Umschläge" and added placeholder text for data loading. Injected `EnvelopeService` and `IJSRuntime` to fetch and log active and completed envelopes. Introduced `_activeEnvelopes` and `_completedEnvelopes` fields to store fetched data. Configured `JsonSerializerOptions` for consistent JSON handling. Implemented `OnInitializedAsync` to fetch data asynchronously, log results to the console, and handle errors gracefully.
This commit is contained in:
@@ -1,7 +1,37 @@
|
||||
@page "/sender"
|
||||
@attribute [Microsoft.AspNetCore.Authorization.Authorize(Policy = "Sender")]
|
||||
|
||||
<h3>EnvelopeSender</h3>
|
||||
@using System.Text.Json
|
||||
@using EnvelopeGenerator.ReceiverUI.Models
|
||||
@inject EnvelopeGenerator.ReceiverUI.Services.EnvelopeService EnvelopeService
|
||||
@inject IJSRuntime JSRuntime
|
||||
|
||||
<h3>Umschläge</h3>
|
||||
|
||||
<p><em>Daten werden geladen und in der Konsole ausgegeben...</em></p>
|
||||
|
||||
@code {
|
||||
private IEnumerable<EnvelopeDto>? _activeEnvelopes;
|
||||
private IEnumerable<EnvelopeDto>? _completedEnvelopes;
|
||||
|
||||
private static readonly JsonSerializerOptions _jsonOptions = new(JsonSerializerDefaults.Web);
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
_activeEnvelopes = await EnvelopeService.GetAsync(onlyActive: true);
|
||||
_completedEnvelopes = await EnvelopeService.GetAsync(onlyCompleted: true);
|
||||
|
||||
await JSRuntime.InvokeVoidAsync("console.log", "----- Aktive Umschläge -----");
|
||||
await JSRuntime.InvokeVoidAsync("console.log", _activeEnvelopes);
|
||||
|
||||
await JSRuntime.InvokeVoidAsync("console.log", "----- Abgeschlossene Umschläge -----");
|
||||
await JSRuntime.InvokeVoidAsync("console.log", _completedEnvelopes);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await JSRuntime.InvokeVoidAsync("console.error", "Fehler beim Laden der Umschläge:", ex.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user