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.
This commit is contained in:
73
src/ReC.Client/Api/ProfileApi.cs
Normal file
73
src/ReC.Client/Api/ProfileApi.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ReC.Client.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides access to profile endpoints.
|
||||
/// </summary>
|
||||
public class ProfileApi
|
||||
{
|
||||
private readonly HttpClient _http;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ProfileApi"/> class.
|
||||
/// </summary>
|
||||
/// <param name="http">The HTTP client used for requests.</param>
|
||||
public ProfileApi(HttpClient http)
|
||||
{
|
||||
_http = http;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a profile by identifier.
|
||||
/// </summary>
|
||||
/// <param name="id">The profile identifier.</param>
|
||||
/// <param name="includeActions">Whether to include related actions.</param>
|
||||
/// <param name="cancel">A token to cancel the operation.</param>
|
||||
/// <returns>The HTTP response message.</returns>
|
||||
public Task<HttpResponseMessage> GetProfileAsync(long id, bool includeActions = false, CancellationToken cancel = default)
|
||||
{
|
||||
var query = ReCClientHelpers.BuildQuery(("Id", id), ("IncludeActions", includeActions));
|
||||
return _http.GetAsync($"api/Profile{query}", cancel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a profile.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The payload type.</typeparam>
|
||||
/// <param name="procedure">The payload to send.</param>
|
||||
/// <param name="cancel">A token to cancel the operation.</param>
|
||||
/// <returns>The HTTP response message.</returns>
|
||||
public Task<HttpResponseMessage> CreateProfileAsync<T>(T procedure, CancellationToken cancel = default)
|
||||
=> _http.PostAsync("api/Profile", ReCClientHelpers.ToJsonContent(procedure), cancel);
|
||||
|
||||
/// <summary>
|
||||
/// Updates a profile.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The payload type.</typeparam>
|
||||
/// <param name="id">The profile identifier.</param>
|
||||
/// <param name="procedure">The payload to send.</param>
|
||||
/// <param name="cancel">A token to cancel the operation.</param>
|
||||
/// <returns>The HTTP response message.</returns>
|
||||
public Task<HttpResponseMessage> UpdateProfileAsync<T>(long id, T procedure, CancellationToken cancel = default)
|
||||
=> _http.PutAsync($"api/Profile/{id}", ReCClientHelpers.ToJsonContent(procedure), cancel);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes profiles.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The payload type containing identifiers.</typeparam>
|
||||
/// <param name="procedure">The payload to send.</param>
|
||||
/// <param name="cancel">A token to cancel the operation.</param>
|
||||
/// <returns>The HTTP response message.</returns>
|
||||
public Task<HttpResponseMessage> DeleteProfilesAsync<T>(T procedure, CancellationToken cancel = default)
|
||||
{
|
||||
var request = new HttpRequestMessage(HttpMethod.Delete, "api/Profile")
|
||||
{
|
||||
Content = ReCClientHelpers.ToJsonContent(procedure)
|
||||
};
|
||||
return _http.SendAsync(request, cancel);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user