summary refs log tree commit diff
path: root/testFrontend
diff options
context:
space:
mode:
Diffstat (limited to 'testFrontend')
-rw-r--r--testFrontend/SafeNSound.FakeUser/Program.cs2
-rw-r--r--testFrontend/SafeNSound.FakeUser/SafeNSound.FakeUser.csproj10
-rw-r--r--testFrontend/SafeNSound.Frontend/Pages/Alarm.razor27
-rw-r--r--testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs8
4 files changed, 44 insertions, 3 deletions
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 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net9.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + +</Project> 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" <h1>Alarm</h1> -<LinkButton OnClick="@RaiseAlarm">Raise alarm</LinkButton> + +<LinkButton OnClick="@RaiseAlarm">Raise</LinkButton> +<LinkButton OnClick="@GetAlarm">Get</LinkButton> +<LinkButton OnClick="@ClearAlarm">Delete</LinkButton> +<LinkButton OnClick="@ClearAlarm">Get all monitored</LinkButton> <br/><br/> @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<AlarmDto>())!; } - 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<Dictionary<string, AlarmDto>> GetAllAlarms() { + var res = await HttpClient.GetAsync("/alarms"); + res.EnsureSuccessStatusCode(); + return (await res.Content.ReadFromJsonAsync<Dictionary<string, AlarmDto>>())!; + } }