From d6c791af681fdcc84c5a79a7b30d35db9231e404 Mon Sep 17 00:00:00 2001 From: Rory& Date: Wed, 11 Jun 2025 07:38:05 +0200 Subject: Add initial demo --- testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs | 53 +++++++++++++------------ 1 file changed, 28 insertions(+), 25 deletions(-) (limited to 'testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs') diff --git a/testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs b/testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs index e1564db..3cd5d5c 100644 --- a/testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs +++ b/testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs @@ -46,18 +46,38 @@ public class SafeNSoundClient(SafeNSoundConfiguration config, string accessToken res.EnsureSuccessStatusCode(); } + public async Task> GetAllAlarms() { + var res = await HttpClient.GetAsync("/alarms"); + res.EnsureSuccessStatusCode(); + return (await res.Content.ReadFromJsonAsync>())!; + } + #endregion #region Budget -#endregion + public async Task AddBudget(string userId, BudgetHistoryEntry budget) { + var res = await HttpClient.PatchAsJsonAsync($"/user/{userId}/budget", budget); + res.EnsureSuccessStatusCode(); + } - public async Task> GetAllAlarms() { - var res = await HttpClient.GetAsync("/alarms"); + public async Task SpendBudget(BudgetHistoryEntry budget) { + var res = await HttpClient.PatchAsJsonAsync($"/budget/@me", budget); res.EnsureSuccessStatusCode(); - return (await res.Content.ReadFromJsonAsync>())!; } + public async Task GetBudget(string userId = "@me") { + var res = await HttpClient.GetAsync( + userId == "@me" + ? $"/budget/@me" + : $"/user/{userId}/budget" + ); + res.EnsureSuccessStatusCode(); + return (await res.Content.ReadFromJsonAsync())!; + } + +#endregion + public async Task DeleteAccount(AuthDto auth) { var res = await HttpClient.DeleteAsJsonAsync("/auth/delete", auth); res.EnsureSuccessStatusCode(); @@ -118,29 +138,12 @@ public class SafeNSoundClient(SafeNSoundConfiguration config, string accessToken var res = await HttpClient.PostAsync("/auth/logout", null); res.EnsureSuccessStatusCode(); } - - public async Task AddBudget(string userId, BudgetHistoryEntry budget) { - var res = await HttpClient.PatchAsJsonAsync($"/user/{userId}/budget", budget); - res.EnsureSuccessStatusCode(); - } - - public async Task SpendBudget(BudgetHistoryEntry budget) { - var res = await HttpClient.PatchAsJsonAsync($"/budget/@me", budget); - res.EnsureSuccessStatusCode(); - } - - public async Task GetBudget(string userId = "@me") { - var res = await HttpClient.GetAsync( - userId == "@me" - ? $"/budget/@me" - : $"/user/{userId}/budget" - ); - res.EnsureSuccessStatusCode(); - return (await res.Content.ReadFromJsonAsync())!; - } } public class AlarmDto { + [JsonPropertyName("_id")] + public string? Id { get; set; } + [JsonPropertyName("reason")] public required string Reason { get; set; } @@ -179,7 +182,7 @@ public class BudgetHistoryEntry { [JsonPropertyName("reason")] public string Reason { get; set; } - + [JsonPropertyName("createdAt")] public DateTime? CreatedAt { get; set; } } \ No newline at end of file -- cgit 1.5.1