summary refs log tree commit diff
path: root/testFrontend/SafeNSound.Sdk
diff options
context:
space:
mode:
Diffstat (limited to 'testFrontend/SafeNSound.Sdk')
-rw-r--r--testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs21
-rw-r--r--testFrontend/SafeNSound.Sdk/WrappedHttpClient.cs4
2 files changed, 10 insertions, 15 deletions
diff --git a/testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs b/testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs

index 4376d3f..e1564db 100644 --- a/testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs +++ b/testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs
@@ -119,15 +119,20 @@ public class SafeNSoundClient(SafeNSoundConfiguration config, string accessToken res.EnsureSuccessStatusCode(); } - public async Task AddBudget(string userId, BudgetWithReason budget) { + 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" + ? $"/budget/@me" : $"/user/{userId}/budget" ); res.EnsureSuccessStatusCode(); @@ -157,16 +162,6 @@ public class DeviceDto { public DateTime LastSeen { get; set; } } -public class Budget { - [JsonPropertyName("budget")] - public double Amount { get; set; } -} - -public class BudgetWithReason : Budget { - [JsonPropertyName("reason")] - public string? Reason { get; set; } -} - public class BudgetWithHistory { [JsonPropertyName("budget")] public double Amount { get; set; } @@ -186,5 +181,5 @@ public class BudgetHistoryEntry { public string Reason { get; set; } [JsonPropertyName("createdAt")] - public DateTime CreatedAt { get; set; } + public DateTime? CreatedAt { get; set; } } \ No newline at end of file diff --git a/testFrontend/SafeNSound.Sdk/WrappedHttpClient.cs b/testFrontend/SafeNSound.Sdk/WrappedHttpClient.cs
index aa785cd..49bd212 100644 --- a/testFrontend/SafeNSound.Sdk/WrappedHttpClient.cs +++ b/testFrontend/SafeNSound.Sdk/WrappedHttpClient.cs
@@ -337,7 +337,7 @@ public class WrappedHttpClient { var request = new HttpRequestMessage(HttpMethod.Delete, url) { - Content = new StringContent(JsonSerializer.Serialize(payload), Encoding.UTF8, "application/json") + Content = new StringContent(JsonSerializer.Serialize(payload, GetJsonSerializerOptions()), Encoding.UTF8, "application/json") }; return await SendAsync(request); } @@ -345,7 +345,7 @@ public class WrappedHttpClient public async Task<HttpResponseMessage> PatchAsJsonAsync<T>(string url, T payload) { var request = new HttpRequestMessage(HttpMethod.Patch, url) { - Content = new StringContent(JsonSerializer.Serialize(payload), Encoding.UTF8, "application/json") + Content = new StringContent(JsonSerializer.Serialize(payload, GetJsonSerializerOptions()), Encoding.UTF8, "application/json") }; return await SendAsync(request); }