summary refs log tree commit diff
path: root/testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-06-11 07:38:05 +0200
committerRory& <root@rory.gay>2025-06-11 07:41:37 +0200
commitd6c791af681fdcc84c5a79a7b30d35db9231e404 (patch)
tree73816b7eda8ff52e7b8b28c9ab68960554d252d3 /testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs
parentAPI docs (diff)
downloadnodejs-final-assignment-d6c791af681fdcc84c5a79a7b30d35db9231e404.tar.xz
Add initial demo
Diffstat (limited to 'testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs')
-rw-r--r--testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs53
1 files changed, 28 insertions, 25 deletions
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<Dictionary<string, AlarmDto>> GetAllAlarms() { + var res = await HttpClient.GetAsync("/alarms"); + res.EnsureSuccessStatusCode(); + return (await res.Content.ReadFromJsonAsync<Dictionary<string, AlarmDto>>())!; + } + #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<Dictionary<string, AlarmDto>> 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<Dictionary<string, AlarmDto>>())!; } + public async Task<BudgetWithHistory> GetBudget(string userId = "@me") { + var res = await HttpClient.GetAsync( + userId == "@me" + ? $"/budget/@me" + : $"/user/{userId}/budget" + ); + res.EnsureSuccessStatusCode(); + return (await res.Content.ReadFromJsonAsync<BudgetWithHistory>())!; + } + +#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<BudgetWithHistory> GetBudget(string userId = "@me") { - var res = await HttpClient.GetAsync( - userId == "@me" - ? $"/budget/@me" - : $"/user/{userId}/budget" - ); - res.EnsureSuccessStatusCode(); - return (await res.Content.ReadFromJsonAsync<BudgetWithHistory>())!; - } } 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