Skip to content

Commit 01c9ab4

Browse files
Get payload by Custom Identifier (#9)
* Added Payload Details to the Server App * Added GetByCustomIdentifierAsync to the XummPayloadClient. Input field has been added to the SignIn flow in the Server App to provide a Custom Identifier which can be used at the Details page to retrieve the payload details.
1 parent 23245bb commit 01c9ab4

File tree

8 files changed

+297
-106
lines changed

8 files changed

+297
-106
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
@page "/payload-details"
2+
@using XUMM.NET.SDK.Clients.Interfaces
3+
@using XUMM.NET.SDK.Models.Payload
4+
@using XUMM.NET.ServerApp.Extensions
5+
@using System.Text.Json
6+
7+
@inject IXummPayloadClient _payloadClient
8+
9+
<PageTitle>Payload Details</PageTitle>
10+
11+
<ResponseAlertBox @ref="_responseAlertBox"></ResponseAlertBox>
12+
13+
<h1>Payload</h1>
14+
<div>Fetch payload details by providing the UUID or Custom Identifier.</div>
15+
16+
<div class="row">
17+
<div class="mb-3">
18+
<label for="payloadUuid" class="form-label">Payload UUID</label>
19+
<input id="payloadUuid" type="text" class="form-control" placeholder="Payload UUID" aria-label="Payload UUID" aria-describedby="basic-addon2" @bind="_payloadUuid">
20+
</div>
21+
<div class="mb-3">
22+
<label for="customIdentifier" class="form-label">Custom Identifier</label>
23+
<input id="customIdentifier" type="text" class="form-control" placeholder="Custom Identifier" aria-label="Custom Identifier" aria-describedby="basic-addon2" @bind="_customIdentifier">
24+
</div>
25+
<div class="btn-group mb-3" role="group">
26+
<button class="btn btn-primary" type="button" @onclick="GetPayloadAsync">Fetch details</button>
27+
</div>
28+
</div>
29+
30+
@if (_payloadDetails != null)
31+
{
32+
<div class="row">
33+
<div class="mb-3">
34+
<h2>Payload details</h2>
35+
<div class="text-break">
36+
<code>@JsonSerializer.SerializeToDocument(_payloadDetails).ToJsonString()</code>
37+
</div>
38+
</div>
39+
</div>
40+
}
41+
42+
@code {
43+
private ResponseAlertBox _responseAlertBox = default!;
44+
private string? _payloadUuid;
45+
private string? _customIdentifier;
46+
private XummPayloadDetails? _payloadDetails;
47+
48+
private async Task GetPayloadAsync()
49+
{
50+
if (!string.IsNullOrWhiteSpace(_payloadUuid))
51+
{
52+
_payloadDetails = await _responseAlertBox.GetResponseAndSetAlertAsync(() => _payloadClient.GetAsync(_payloadUuid));
53+
}
54+
else if (!string.IsNullOrWhiteSpace(_customIdentifier))
55+
{
56+
_payloadDetails = await _responseAlertBox.GetResponseAndSetAlertAsync(() => _payloadClient.GetByCustomIdentifierAsync(_customIdentifier));
57+
}
58+
59+
_responseAlertBox.SetAlert("Payload Details", _payloadDetails != null);
60+
}
61+
}
Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
using System.Text;
22
using System.Text.Json;
33

4-
namespace XUMM.NET.ServerApp.Extensions
4+
namespace XUMM.NET.ServerApp.Extensions;
5+
6+
public static class JsonDocumentExtensions
57
{
6-
public static class JsonDocumentExtensions
8+
public static string? ToJsonString(this JsonDocument? jsonDocument)
79
{
8-
public static string? ToJsonString(this JsonDocument? jsonDocument)
10+
if (jsonDocument == null)
911
{
10-
if (jsonDocument == null)
11-
{
12-
return null;
13-
}
14-
15-
using var stream = new MemoryStream();
16-
var writer = new Utf8JsonWriter(stream, new JsonWriterOptions
17-
{
18-
Indented = true
19-
});
20-
jsonDocument.WriteTo(writer);
21-
writer.Flush();
22-
return Encoding.UTF8.GetString(stream.ToArray());
12+
return null;
2313
}
14+
15+
using var stream = new MemoryStream();
16+
var writer = new Utf8JsonWriter(stream, new JsonWriterOptions
17+
{
18+
Indented = true
19+
});
20+
jsonDocument.WriteTo(writer);
21+
writer.Flush();
22+
return Encoding.UTF8.GetString(stream.ToArray());
2423
}
2524
}

examples/XUMM.Net.ServerApp/Pages/Payload/SignIn.razor

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
}
4242
else
4343
{
44+
<div class="mb-3">
45+
<label for="customIdentifier" class="form-label">Custom Identifier</label>
46+
<input id="customIdentifier" type="text" class="form-control" placeholder="Custom Identifier" aria-label="Custom Identifier" aria-describedby="basic-addon2" @bind="_customIdentifier">
47+
</div>
4448
<div class="btn-group mb-3" role="group">
4549
<button class="btn btn-primary" @onclick="CreatePayloadAndSubscribe">Create payload and subscribe</button>
4650
</div>
@@ -84,6 +88,7 @@
8488
private readonly List<string> _messages = new();
8589
private string? _qrCodeUrl;
8690
private string? _payloadUuid;
91+
private string? _customIdentifier;
8792
private bool? _signed;
8893

8994
private async Task CreatePayloadAndSubscribe()
@@ -95,6 +100,11 @@
95100
CustomMeta = new XummPayloadCustomMeta { Instruction = "Test payload created with the XUMM.NET SDK." }
96101
};
97102

103+
if (!string.IsNullOrWhiteSpace(_customIdentifier))
104+
{
105+
payload.CustomMeta.Identifier = _customIdentifier;
106+
}
107+
98108
var payloadResult = await _payloadClient.CreateAsync(payload);
99109

100110
if (payloadResult != null)
@@ -115,7 +125,7 @@
115125
{
116126
_cts.Cancel();
117127
_qrCodeUrl = null;
118-
_messages.Add($"Payload {_payloadUuid} subscription cancelled.");
128+
_messages.Add($"Payload {_payloadUuid} subscription cancelled.");
119129
StateHasChanged();
120130
}
121131

examples/XUMM.Net.ServerApp/Shared/NavMenu.razor

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,12 @@
6363
<NavLink class="nav-link ps-4" href="/signin">
6464
<span class="oi oi-account-login" aria-hidden="true"></span> Sign In
6565
</NavLink>
66-
<NavLink class="nav-link ps-4" href="/custom-json">
66+
<NavLink class="nav-link ps-4" href="/custom-json">
6767
<span class="oi oi-document" aria-hidden="true"></span> Custom JSON
6868
</NavLink>
69+
<NavLink class="nav-link ps-4" href="/payload-details">
70+
<span class="oi oi-list" aria-hidden="true"></span> Details
71+
</NavLink>
6972
}
7073
</div>
7174
</nav>

0 commit comments

Comments
 (0)