Files
EnvelopeGenerator/EnvelopeGenerator.ReceiverUI/Pages/EnvelopeSenderPage.razor
TekH e4ebb29969 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.
2026-06-15 16:24:45 +02:00

37 lines
1.3 KiB
Plaintext

@page "/sender"
@attribute [Microsoft.AspNetCore.Authorization.Authorize(Policy = "Sender")]
@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());
}
}
}