From 9c46b9f2da8f6486d122190f14eb08a9674b4914 Mon Sep 17 00:00:00 2001 From: TekH Date: Fri, 16 Jan 2026 11:32:44 +0100 Subject: [PATCH] Add ProfileApi for profile CRUD operations via HttpClient Introduced ProfileApi class in ReC.Client.Api to handle profile-related API endpoints. Supports retrieving, creating, updating, and deleting profiles using an injected HttpClient. Methods accept cancellation tokens and utilize helper methods for query building and JSON serialization. Includes XML documentation for all methods and parameters. --- src/ReC.Client/Api/ProfileApi.cs | 73 ++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/ReC.Client/Api/ProfileApi.cs diff --git a/src/ReC.Client/Api/ProfileApi.cs b/src/ReC.Client/Api/ProfileApi.cs new file mode 100644 index 0000000..2c3cc19 --- /dev/null +++ b/src/ReC.Client/Api/ProfileApi.cs @@ -0,0 +1,73 @@ +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +namespace ReC.Client.Api +{ + /// + /// Provides access to profile endpoints. + /// + public class ProfileApi + { + private readonly HttpClient _http; + + /// + /// Initializes a new instance of the class. + /// + /// The HTTP client used for requests. + public ProfileApi(HttpClient http) + { + _http = http; + } + + /// + /// Retrieves a profile by identifier. + /// + /// The profile identifier. + /// Whether to include related actions. + /// A token to cancel the operation. + /// The HTTP response message. + public Task GetProfileAsync(long id, bool includeActions = false, CancellationToken cancel = default) + { + var query = ReCClientHelpers.BuildQuery(("Id", id), ("IncludeActions", includeActions)); + return _http.GetAsync($"api/Profile{query}", cancel); + } + + /// + /// Creates a profile. + /// + /// The payload type. + /// The payload to send. + /// A token to cancel the operation. + /// The HTTP response message. + public Task CreateProfileAsync(T procedure, CancellationToken cancel = default) + => _http.PostAsync("api/Profile", ReCClientHelpers.ToJsonContent(procedure), cancel); + + /// + /// Updates a profile. + /// + /// The payload type. + /// The profile identifier. + /// The payload to send. + /// A token to cancel the operation. + /// The HTTP response message. + public Task UpdateProfileAsync(long id, T procedure, CancellationToken cancel = default) + => _http.PutAsync($"api/Profile/{id}", ReCClientHelpers.ToJsonContent(procedure), cancel); + + /// + /// Deletes profiles. + /// + /// The payload type containing identifiers. + /// The payload to send. + /// A token to cancel the operation. + /// The HTTP response message. + public Task DeleteProfilesAsync(T procedure, CancellationToken cancel = default) + { + var request = new HttpRequestMessage(HttpMethod.Delete, "api/Profile") + { + Content = ReCClientHelpers.ToJsonContent(procedure) + }; + return _http.SendAsync(request, cancel); + } + } +}