From b639df0a39b448e64cf1d8f97e41104d0c19dafa Mon Sep 17 00:00:00 2001 From: TekH Date: Fri, 16 Jan 2026 11:33:51 +0100 Subject: [PATCH] Add ResultApi for HTTP access to output result endpoints Introduced the ResultApi class in the ReC.Client.Api namespace to provide asynchronous methods for retrieving, creating, updating, and deleting output results via HTTP. The class uses an injected HttpClient, supports cancellation tokens, and leverages helper methods for query construction and JSON serialization. --- src/ReC.Client/Api/ResultApi.cs | 74 +++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/ReC.Client/Api/ResultApi.cs diff --git a/src/ReC.Client/Api/ResultApi.cs b/src/ReC.Client/Api/ResultApi.cs new file mode 100644 index 0000000..4ad84f0 --- /dev/null +++ b/src/ReC.Client/Api/ResultApi.cs @@ -0,0 +1,74 @@ +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +namespace ReC.Client.Api +{ + /// + /// Provides access to output result endpoints. + /// + public class ResultApi + { + private readonly HttpClient _http; + + /// + /// Initializes a new instance of the class. + /// + /// The HTTP client used for requests. + public ResultApi(HttpClient http) + { + _http = http; + } + + /// + /// Retrieves results with optional filters. + /// + /// Optional result identifier. + /// Optional action identifier. + /// Optional profile identifier. + /// A token to cancel the operation. + /// The HTTP response message. + public Task GetResultsAsync(long? id = null, long? actionId = null, long? profileId = null, CancellationToken cancel = default) + { + var query = ReCClientHelpers.BuildQuery(("Id", id), ("ActionId", actionId), ("ProfileId", profileId)); + return _http.GetAsync($"api/OutRes{query}", cancel); + } + + /// + /// Creates a result. + /// + /// The payload type. + /// The payload to send. + /// A token to cancel the operation. + /// The HTTP response message. + public Task CreateResultAsync(T procedure, CancellationToken cancel = default) + => _http.PostAsync("api/OutRes", ReCClientHelpers.ToJsonContent(procedure), cancel); + + /// + /// Updates a result. + /// + /// The payload type. + /// The result identifier. + /// The payload to send. + /// A token to cancel the operation. + /// The HTTP response message. + public Task UpdateResultAsync(long id, T procedure, CancellationToken cancel = default) + => _http.PutAsync($"api/OutRes/{id}", ReCClientHelpers.ToJsonContent(procedure), cancel); + + /// + /// Deletes results. + /// + /// The payload type containing identifiers. + /// The payload to send. + /// A token to cancel the operation. + /// The HTTP response message. + public Task DeleteResultsAsync(T procedure, CancellationToken cancel = default) + { + var request = new HttpRequestMessage(HttpMethod.Delete, "api/OutRes") + { + Content = ReCClientHelpers.ToJsonContent(procedure) + }; + return _http.SendAsync(request, cancel); + } + } +}