From 5197ad1481a075a2588b56ef9e04b06d83a12567 Mon Sep 17 00:00:00 2001 From: TekH Date: Fri, 16 Jan 2026 12:29:17 +0100 Subject: [PATCH] Refactor BaseCrudApi to use generic type parameters BaseCrudApi is now defined as BaseCrudApi, with each CRUD method using its respective type parameter. This improves type safety and clarity for API payloads. Method signatures and XML documentation have been updated accordingly. --- src/ReC.Client/Api/BaseCrudApi.cs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/ReC.Client/Api/BaseCrudApi.cs b/src/ReC.Client/Api/BaseCrudApi.cs index cce0594..f12b6ab 100644 --- a/src/ReC.Client/Api/BaseCrudApi.cs +++ b/src/ReC.Client/Api/BaseCrudApi.cs @@ -8,7 +8,7 @@ namespace ReC.Client.Api /// /// Provides shared CRUD operations for API resources. /// - public abstract class BaseCrudApi + public abstract class BaseCrudApi { /// /// The HTTP client used to send requests. @@ -21,7 +21,7 @@ namespace ReC.Client.Api protected readonly string ResourcePath; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The HTTP client used for requests. /// The base resource path for the API endpoint. @@ -34,32 +34,29 @@ namespace ReC.Client.Api /// /// Creates a resource. /// - /// The payload type. /// The payload to send. /// A token to cancel the operation. /// The HTTP response message. - public Task CreateAsync(T payload, CancellationToken cancel = default) + public Task CreateAsync(TCreate payload, CancellationToken cancel = default) => Http.PostAsync(ResourcePath, ReCClientHelpers.ToJsonContent(payload), cancel); /// /// Updates a resource by identifier. /// - /// The payload type. /// The resource identifier. /// The payload to send. /// A token to cancel the operation. /// The HTTP response message. - public Task UpdateAsync(long id, T payload, CancellationToken cancel = default) + public Task UpdateAsync(long id, TUpdate payload, CancellationToken cancel = default) => Http.PutAsync($"{ResourcePath}/{id}", ReCClientHelpers.ToJsonContent(payload), cancel); /// /// Deletes resources with identifiers supplied in the payload. /// - /// The payload type containing identifiers. /// The payload to send. /// A token to cancel the operation. /// The HTTP response message. - public Task DeleteAsync(T payload, CancellationToken cancel = default) + public Task DeleteAsync(TDelete payload, CancellationToken cancel = default) { var request = new HttpRequestMessage(HttpMethod.Delete, ResourcePath) {