Introduce BaseCrudApi to encapsulate common CRUD logic for API resource classes. Refactor CommonApi, EndpointAuthApi, EndpointParamsApi, EndpointsApi, ProfileApi, RecActionApi, and ResultApi to inherit from BaseCrudApi, removing duplicated CRUD methods and constructors. This centralizes CRUD operations, reduces code duplication, and improves maintainability.
34 lines
1.2 KiB
C#
34 lines
1.2 KiB
C#
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 : BaseCrudApi
|
|
{
|
|
/// <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) : base(http, "api/Profile")
|
|
{
|
|
}
|
|
|
|
/// <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> GetAsync(long id, bool includeActions = false, CancellationToken cancel = default)
|
|
{
|
|
var query = ReCClientHelpers.BuildQuery(("Id", id), ("IncludeActions", includeActions));
|
|
return Http.GetAsync($"{ResourcePath}{query}", cancel);
|
|
}
|
|
}
|
|
}
|