From 073248777a6414505b1df7f65a0cb1dcf5c44118 Mon Sep 17 00:00:00 2001 From: Rory& Date: Sun, 1 Jun 2025 09:23:16 +0200 Subject: Update test client --- testFrontend/SafeNSound.Frontend/Pages/Auth.razor | 9 +++---- .../SafeNSound.Sdk/SafeNSoundAuthentication.cs | 31 +++++++++++++++++----- testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs | 2 +- 3 files changed, 29 insertions(+), 13 deletions(-) (limited to 'testFrontend') diff --git a/testFrontend/SafeNSound.Frontend/Pages/Auth.razor b/testFrontend/SafeNSound.Frontend/Pages/Auth.razor index 6c28bf1..3db77a1 100644 --- a/testFrontend/SafeNSound.Frontend/Pages/Auth.razor +++ b/testFrontend/SafeNSound.Frontend/Pages/Auth.razor @@ -1,6 +1,5 @@ @page "/Auth" -

Auth

Username (L?, R): @@ -8,7 +7,7 @@ Email (L? R):
Password (L, R): -
+
Type (R): (one of user|monitor|admin)
Randomise @@ -46,7 +45,7 @@ private async Task Randomise() { Username = Guid.NewGuid().ToString(); - Email = Guid.NewGuid().ToString() + "@example.com"; + Email = Guid.NewGuid() + "@example.com"; Password = Guid.NewGuid().ToString(); UserType = Random.Shared.GetItems(["user", "monitor", "admin"], 1)[0]; StateHasChanged(); @@ -56,7 +55,7 @@ Result = null; Exception = null; try { - Result = await Authentication.Register(new() { + await Authentication.Register(new() { Username = Username, Password = Password, Email = Email, @@ -91,7 +90,7 @@ Result = null; Exception = null; try { - Result = await Authentication.Delete(new() { + await Authentication.Delete(new() { Username = Username, Password = Password, Email = Email diff --git a/testFrontend/SafeNSound.Sdk/SafeNSoundAuthentication.cs b/testFrontend/SafeNSound.Sdk/SafeNSoundAuthentication.cs index cbff880..f63d8b0 100644 --- a/testFrontend/SafeNSound.Sdk/SafeNSoundAuthentication.cs +++ b/testFrontend/SafeNSound.Sdk/SafeNSoundAuthentication.cs @@ -1,15 +1,16 @@ -using System.Text.Json.Serialization; +using System.Net.Http.Json; +using System.Text.Json.Serialization; namespace SafeNSound.Sdk; public class SafeNSoundAuthentication(SafeNSoundConfiguration config) { - public async Task Register(RegisterDto registerDto) { + public async Task Register(RegisterDto registerDto) { var hc = new WrappedHttpClient() { BaseAddress = new Uri(config.BaseUri) }; var res = await hc.PostAsJsonAsync("/auth/register", registerDto); - return null!; + res.EnsureSuccessStatusCode(); } public async Task Login(AuthDto authDto) { @@ -18,17 +19,16 @@ public class SafeNSoundAuthentication(SafeNSoundConfiguration config) { }; var res = await hc.PostAsJsonAsync("/auth/login", authDto); - return null!; + return (await res.Content.ReadFromJsonAsync())!; } - public async Task Delete(AuthDto authDto) { + public async Task Delete(AuthDto authDto) { var hc = new WrappedHttpClient() { BaseAddress = new Uri(config.BaseUri) }; var res = await hc.DeleteAsJsonAsync("/auth/delete", authDto); res.EnsureSuccessStatusCode(); - return null!; } } @@ -57,4 +57,21 @@ public class AuthDto { public string Email { get; set; } = string.Empty; } -public class SafeNSoundAuthResult { } \ No newline at end of file +public class WhoAmI { + [JsonPropertyName("userId")] + public required string UserId { get; set; } + + [JsonPropertyName("username")] + public required string UserName { get; set; } + + [JsonPropertyName("deviceId")] + public required string DeviceId { get; set; } + + [JsonPropertyName("type")] + public required string UserType { get; set; } +} + +public class SafeNSoundAuthResult : WhoAmI { + [JsonPropertyName("accessToken")] + public required string AccessToken { get; set; } +} \ No newline at end of file diff --git a/testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs b/testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs index 7a7023c..dee3913 100644 --- a/testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs +++ b/testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs @@ -1,6 +1,6 @@ namespace SafeNSound.Sdk; -public class SafeNSoundClient +public class SafeNSoundClient(SafeNSoundConfiguration config) { } \ No newline at end of file -- cgit 1.5.1