From 1c2427084ba610553c49140a2ce604fa63ba37c9 Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Thu, 7 May 2026 23:07:45 +1000 Subject: v0.14a --- ApiClient.csproj | 4 ++-- HyperBooru.cs | 2 ++ User.cs | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 User.cs diff --git a/ApiClient.csproj b/ApiClient.csproj index 8cfe843..db8e34a 100644 --- a/ApiClient.csproj +++ b/ApiClient.csproj @@ -7,9 +7,9 @@ HyperBooru.ApiClient HyperBooru.ApiClient HyperBooru.ApiClient - 0.13.0.0 + 0.14.0.0 $(AssemblyVersion) - 0.13-alpha + 0.14-alpha diff --git a/HyperBooru.cs b/HyperBooru.cs index dac901a..4c41d96 100644 --- a/HyperBooru.cs +++ b/HyperBooru.cs @@ -7,6 +7,7 @@ namespace HyperBooru.ApiClient; public sealed class HBSession : IDisposable { public Media Media { get; private init; } public Tag Tag { get; private init; } + public User User { get; private init; } public Uri BaseUri { get; private init; } internal HttpClient HttpClient { get; private init; } @@ -35,6 +36,7 @@ public sealed class HBSession : IDisposable { Media = new(this); Tag = new(this); + User = new(this); } public async Task LoginAsync(string username, string password) { 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