diff --git a/testFrontend/SafeNSound.Sdk/SafeNSoundAuthentication.cs b/testFrontend/SafeNSound.Sdk/SafeNSoundAuthentication.cs
index 333db6d..d0ed245 100644
--- a/testFrontend/SafeNSound.Sdk/SafeNSoundAuthentication.cs
+++ b/testFrontend/SafeNSound.Sdk/SafeNSoundAuthentication.cs
@@ -13,13 +13,13 @@ public class SafeNSoundAuthentication(SafeNSoundConfiguration config) {
res.EnsureSuccessStatusCode();
}
- public async Task<SafeNSoundAuthResult> Login(AuthDto authDto) {
+ public async Task<AuthResult> Login(AuthDto authDto) {
var hc = new WrappedHttpClient() {
BaseAddress = new Uri(config.BaseUri)
};
var res = await hc.PostAsJsonAsync("/auth/login", authDto);
- return (await res.Content.ReadFromJsonAsync<SafeNSoundAuthResult>())!;
+ return (await res.Content.ReadFromJsonAsync<AuthResult>())!;
}
public async Task Delete(AuthDto authDto) {
@@ -32,16 +32,7 @@ public class SafeNSoundAuthentication(SafeNSoundConfiguration config) {
}
}
-public class RegisterDto {
- [JsonPropertyName("username")]
- public string Username { get; set; } = string.Empty;
-
- [JsonPropertyName("password")]
- public string Password { get; set; } = string.Empty;
-
- [JsonPropertyName("email")]
- public string Email { get; set; } = string.Empty;
-
+public class RegisterDto : AuthDto {
[JsonPropertyName("type")]
public string UserType { get; set; } = string.Empty;
}
@@ -68,7 +59,7 @@ public class WhoAmI {
public required string UserType { get; set; }
}
-public class SafeNSoundAuthResult : WhoAmI {
+public class AuthResult : WhoAmI {
[JsonPropertyName("accessToken")]
public required string AccessToken { get; set; }
}
\ No newline at end of file
diff --git a/testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs b/testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs
index c6f16f2..8291178 100644
--- a/testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs
+++ b/testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs
@@ -1,4 +1,5 @@
using System.Net.Http.Json;
+using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
namespace SafeNSound.Sdk;
@@ -54,10 +55,47 @@ public class SafeNSoundClient(SafeNSoundConfiguration config, string accessToken
res.EnsureSuccessStatusCode();
return (await res.Content.ReadFromJsonAsync<Dictionary<string, AlarmDto>>())!;
}
+
+ public async Task DeleteAccount(AuthDto auth) {
+ var res = await HttpClient.DeleteAsJsonAsync("/auth/delete", auth);
+ res.EnsureSuccessStatusCode();
+ }
+
+ public async Task<List<string>> GetAssignedUsers() {
+ var res = await HttpClient.GetAsync("/monitor/assignedUsers");
+ res.EnsureSuccessStatusCode();
+ return (await res.Content.ReadFromJsonAsync<List<string>>())!;
+ }
+
+ public async Task AddAssignedUser(string targetUserId) {
+ var res = await HttpClient.PatchAsJsonAsync("/monitor/assignedUsers", new { userId = targetUserId });
+ res.EnsureSuccessStatusCode();
+ }
+
+ public async Task RemoveAssignedUser(string targetUserId) {
+ var res = await HttpClient.DeleteAsJsonAsync($"/monitor/assignedUsers", new { userId = targetUserId });
+ res.EnsureSuccessStatusCode();
+ }
+
+ public async IAsyncEnumerable<string> GetAllUserIdsEnumerable() {
+ var res = await HttpClient.GetAsync($"/admin/allUserIds");
+ res.EnsureSuccessStatusCode();
+ await foreach (var item in res.Content.ReadFromJsonAsAsyncEnumerable<string>()) {
+ yield return item!;
+ }
+ }
+
+ public async Task MonitorAllUsers() {
+ var res = await HttpClient.PostAsync("/admin/monitorAllUsers", null);
+ res.EnsureSuccessStatusCode();
+ }
}
public class AlarmDto {
[JsonPropertyName("reason")]
public required string Reason { get; set; }
+
+ [JsonPropertyName("createdAt")]
+ 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 e4b4500..aa785cd 100644
--- a/testFrontend/SafeNSound.Sdk/WrappedHttpClient.cs
+++ b/testFrontend/SafeNSound.Sdk/WrappedHttpClient.cs
@@ -157,12 +157,15 @@ public class WrappedHttpClient
"Access-Control-Allow-Methods",
"Access-Control-Allow-Headers",
"Access-Control-Expose-Headers",
+ "Access-Control-Allow-Credentials",
"Cache-Control",
"Cross-Origin-Resource-Policy",
"X-Content-Security-Policy",
"Referrer-Policy",
"X-Robots-Tag",
- "Content-Security-Policy"
+ "Content-Security-Policy",
+ "Keep-Alive",
+ "ETag"
]));
return responseMessage;
@@ -338,4 +341,12 @@ public class WrappedHttpClient
};
return await SendAsync(request);
}
+
+ 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")
+ };
+ return await SendAsync(request);
+ }
}
\ No newline at end of file
|