From 197f7d362be4a947b1951ed560223527f8c16449 Mon Sep 17 00:00:00 2001 From: Rory& Date: Mon, 2 Jun 2025 19:38:34 +0200 Subject: More alarm testing --- testFrontend/SafeNSound.FakeUser/Program.cs | 2 ++ .../SafeNSound.FakeUser/SafeNSound.FakeUser.csproj | 10 ++++++++ testFrontend/SafeNSound.Frontend/Pages/Alarm.razor | 27 ++++++++++++++++++++-- testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs | 8 ++++++- 4 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 testFrontend/SafeNSound.FakeUser/Program.cs create mode 100644 testFrontend/SafeNSound.FakeUser/SafeNSound.FakeUser.csproj (limited to 'testFrontend') diff --git a/testFrontend/SafeNSound.FakeUser/Program.cs b/testFrontend/SafeNSound.FakeUser/Program.cs new file mode 100644 index 0000000..3751555 --- /dev/null +++ b/testFrontend/SafeNSound.FakeUser/Program.cs @@ -0,0 +1,2 @@ +// See https://aka.ms/new-console-template for more information +Console.WriteLine("Hello, World!"); diff --git a/testFrontend/SafeNSound.FakeUser/SafeNSound.FakeUser.csproj b/testFrontend/SafeNSound.FakeUser/SafeNSound.FakeUser.csproj new file mode 100644 index 0000000..fd4bd08 --- /dev/null +++ b/testFrontend/SafeNSound.FakeUser/SafeNSound.FakeUser.csproj @@ -0,0 +1,10 @@ + + + + Exe + net9.0 + enable + enable + + + diff --git a/testFrontend/SafeNSound.Frontend/Pages/Alarm.razor b/testFrontend/SafeNSound.Frontend/Pages/Alarm.razor index 71d18f2..59b8e4c 100644 --- a/testFrontend/SafeNSound.Frontend/Pages/Alarm.razor +++ b/testFrontend/SafeNSound.Frontend/Pages/Alarm.razor @@ -1,7 +1,11 @@ @page "/Alarm"

Alarm

-Raise alarm + +Raise +Get +Delete +Get all monitored

@if (Exception != null) { @@ -25,7 +29,8 @@ @code { private Exception? Exception { get; set; } private object? Result { get; set; } - + private string UserId { get; set; } = "@me"; + protected override async Task OnInitializedAsync() { if (App.Client is null) { NavigationManager.NavigateTo("/Auth"); @@ -34,9 +39,27 @@ } private async Task RaiseAlarm() { + Result = null; await App.Client!.SetAlarm(new() { Reason = "fall" }); + StateHasChanged(); + } + + private async Task GetAlarm() { + Result = null; + Result = await App.Client!.GetAlarm(UserId); + StateHasChanged(); + } + + private async Task ClearAlarm() { + Result = null; + await App.Client!.DeleteAlarm(UserId); + StateHasChanged(); + } + + private async Task GetAllAlarms() { + Result = await App.Client.GetAllAlarms(); } } \ No newline at end of file diff --git a/testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs b/testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs index 444e313..c6f16f2 100644 --- a/testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs +++ b/testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs @@ -29,7 +29,7 @@ public class SafeNSoundClient(SafeNSoundConfiguration config, string accessToken return (await res.Content.ReadFromJsonAsync())!; } - public async Task SetAlarm(AlarmDto alarm) { + public async Task SetAlarm(AlarmDto alarm, string userId = "@me") { var res = await HttpClient.PutAsJsonAsync("/alarm/@me", alarm); res.EnsureSuccessStatusCode(); } @@ -48,6 +48,12 @@ public class SafeNSoundClient(SafeNSoundConfiguration config, string accessToken #endregion + + public async Task> GetAllAlarms() { + var res = await HttpClient.GetAsync("/alarms"); + res.EnsureSuccessStatusCode(); + return (await res.Content.ReadFromJsonAsync>())!; + } } -- cgit 1.5.1