From 1c2427084ba610553c49140a2ce604fa63ba37c9 Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Thu, 7 May 2026 23:07:45 +1000 Subject: v0.14a --- User.cs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 User.cs (limited to 'User.cs') diff --git a/User.cs b/User.cs new file mode 100644 index 0000000..f1e6d6f --- /dev/null +++ b/User.cs @@ -0,0 +1,41 @@ +using System.Net.Http.Json; + +namespace HyperBooru.ApiClient; + +public class User { + private HBSession session; + + internal User(HBSession session) => + this.session = session; + + public async Task GetAllUsersAsync() => + (await session.HttpClient.GetFromJsonAsync("/api/user"))!; + + public async Task GetUserAsync(Guid userId) => + (await session.HttpClient.GetFromJsonAsync($"/api/user/{userId}"))!; + + public async Task CreateUserAsync(string username, string password) { + var user = new ApiModels.UserCreateRequest() { + Username = username, + Password = password + }; + + var response = await session.HttpClient.PostAsJsonAsync("/api/user", user); + + return (await response.Content.ReadFromJsonAsync())!; + } + + public async Task UpdateUserAsync(Guid userId, string? username, string? password) { + var user = new ApiModels.UserUpdateRequest() { + Username = username, + Password = password + }; + + var response = await session.HttpClient.PatchAsJsonAsync($"/api/user/{userId}", user); + + return (await response.Content.ReadFromJsonAsync())!; + } + + public async Task DeleteUserAsync(Guid userId) => + (await session.HttpClient.DeleteFromJsonAsync($"/api/user/{userId}"))!; +} -- cgit v1.3