diff --git a/EstateReportingAPI.Client/EstateReportingApiClient.cs b/EstateReportingAPI.Client/EstateReportingApiClient.cs index 6e49e64..0fe1a86 100644 --- a/EstateReportingAPI.Client/EstateReportingApiClient.cs +++ b/EstateReportingAPI.Client/EstateReportingApiClient.cs @@ -18,11 +18,6 @@ namespace EstateReportingAPI.Client{ using Microsoft.AspNetCore.Http; using Newtonsoft.Json; - internal class ResponseData - { - public T Data { get; set; } - } - public class EstateReportingApiClient : ClientProxyBase, IEstateReportingApiClient{ #region Fields @@ -54,9 +49,17 @@ public async Task>> GetCalendarDates(String accessToke // Make the Http Call here HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(request, cancellationToken); - + // Process the response - return await ProcessResponse>(httpResponse, cancellationToken); + Result result = await this.HandleResponseX(httpResponse, cancellationToken); + + if (result.IsFailed) + return ResultHelpers.CreateFailure(result); + + // call was successful so now deserialise the body to the response object + ResponseData> responseData = this.HandleResponseContent>(result.Data); + + return Result.Success(responseData.Data); } catch(Exception ex){ // An exception has occurred, add some additional information to the message @@ -65,16 +68,6 @@ public async Task>> GetCalendarDates(String accessToke return Result.Failure(exception.Message); } } - - private async Task> ProcessResponse(HttpResponseMessage httpResponse, CancellationToken cancellationToken) { - Result result = await this.HandleResponseX(httpResponse, cancellationToken); - if (result.IsFailed) - return ResultHelpers.CreateFailure(result); - - ResponseData response = JsonConvert.DeserializeObject>(result.Data); - - return Result.Success(response.Data); - } public async Task>> GetCalendarYears(String accessToken, Guid estateId, CancellationToken cancellationToken){ @@ -89,7 +82,15 @@ public async Task>> GetCalendarYears(String accessToke HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(request, cancellationToken); // Process the response - return await ProcessResponse>(httpResponse, cancellationToken); + Result result = await this.HandleResponseX(httpResponse, cancellationToken); + + if (result.IsFailed) + return ResultHelpers.CreateFailure(result); + + // call was successful so now deserialise the body to the response object + ResponseData> responseData = this.HandleResponseContent>(result.Data); + + return Result.Success(responseData.Data); } catch(Exception ex){ // An exception has occurred, add some additional information to the message @@ -111,7 +112,15 @@ public async Task>> GetComparisonDates(String access HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(request, cancellationToken); // Process the response - return await ProcessResponse>(httpResponse, cancellationToken); + Result result = await this.HandleResponseX(httpResponse, cancellationToken); + + if (result.IsFailed) + return ResultHelpers.CreateFailure(result); + + // call was successful so now deserialise the body to the response object + ResponseData> responseData = this.HandleResponseContent>(result.Data); + + return Result.Success(responseData.Data); } catch(Exception ex){ // An exception has occurred, add some additional information to the message @@ -135,7 +144,15 @@ public async Task> GetLastSettlement(String accessToken, HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(request, cancellationToken); // Process the response - return await ProcessResponse(httpResponse, cancellationToken); + Result result = await this.HandleResponseX(httpResponse, cancellationToken); + + if (result.IsFailed) + return ResultHelpers.CreateFailure(result); + + // call was successful so now deserialise the body to the response object + ResponseData responseData = this.HandleResponseContent(result.Data); + + return Result.Success(responseData.Data); } catch(Exception ex){ // An exception has occurred, add some additional information to the message @@ -160,7 +177,15 @@ public async Task>> GetResponseCodes(String accessToke HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(request, cancellationToken); // Process the response - return await ProcessResponse>(httpResponse, cancellationToken); + Result result = await this.HandleResponseX(httpResponse, cancellationToken); + + if (result.IsFailed) + return ResultHelpers.CreateFailure(result); + + // call was successful so now deserialise the body to the response object + ResponseData> responseData = this.HandleResponseContent>(result.Data); + + return Result.Success(responseData.Data); } catch (Exception ex) { @@ -188,7 +213,15 @@ public async Task> GetMerchantPerformance(String accessToken HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(request, cancellationToken); // Process the response - return await ProcessResponse(httpResponse, cancellationToken); + Result result = await this.HandleResponseX(httpResponse, cancellationToken); + + if (result.IsFailed) + return ResultHelpers.CreateFailure(result); + + // call was successful so now deserialise the body to the response object + ResponseData responseData = this.HandleResponseContent(result.Data); + + return Result.Success(responseData.Data); } catch (Exception ex) { @@ -215,7 +248,16 @@ public async Task> GetProductPerformance(String accessToken, HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(request, cancellationToken); // Process the response - return await ProcessResponse(httpResponse, cancellationToken); + // Process the response + Result result = await this.HandleResponseX(httpResponse, cancellationToken); + + if (result.IsFailed) + return ResultHelpers.CreateFailure(result); + + // call was successful so now deserialise the body to the response object + ResponseData responseData = this.HandleResponseContent(result.Data); + + return Result.Success(responseData.Data); } catch (Exception ex) { @@ -240,7 +282,16 @@ public async Task>> GetMerchantsByLastSaleDate(String acce HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(request, cancellationToken); // Process the response - return await ProcessResponse>(httpResponse, cancellationToken); + // Process the response + Result result = await this.HandleResponseX(httpResponse, cancellationToken); + + if (result.IsFailed) + return ResultHelpers.CreateFailure(result); + + // call was successful so now deserialise the body to the response object + ResponseData> responseData = this.HandleResponseContent>(result.Data); + + return Result.Success(responseData.Data); } catch (Exception ex) { @@ -267,7 +318,16 @@ public async Task> GetOperatorPerformance(String accessToken HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(request, cancellationToken); // Process the response - return await ProcessResponse(httpResponse, cancellationToken); + // Process the response + Result result = await this.HandleResponseX(httpResponse, cancellationToken); + + if (result.IsFailed) + return ResultHelpers.CreateFailure(result); + + // call was successful so now deserialise the body to the response object + ResponseData responseData = this.HandleResponseContent(result.Data); + + return Result.Success(responseData.Data); } catch (Exception ex) { @@ -310,7 +370,15 @@ public async Task>> TransactionSearch(String acce HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(request, cancellationToken); // Process the response - return await ProcessResponse>(httpResponse, cancellationToken); + Result result = await this.HandleResponseX(httpResponse, cancellationToken); + + if (result.IsFailed) + return ResultHelpers.CreateFailure(result); + + // call was successful so now deserialise the body to the response object + ResponseData> responseData = this.HandleResponseContent>(result.Data); + + return Result.Success(responseData.Data); } catch (Exception ex) { @@ -356,7 +424,16 @@ public async Task>> GetUnsettledFees(String accessToke HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(request, cancellationToken); // Process the response - return await ProcessResponse>(httpResponse, cancellationToken); + // Process the response + Result result = await this.HandleResponseX(httpResponse, cancellationToken); + + if (result.IsFailed) + return ResultHelpers.CreateFailure(result); + + // call was successful so now deserialise the body to the response object + ResponseData> responseData = this.HandleResponseContent>(result.Data); + + return Result.Success(responseData.Data); } catch (Exception ex) { @@ -380,7 +457,15 @@ public async Task> GetMerchantKpi(String accessToken, Guid e HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(request, cancellationToken); // Process the response - return await ProcessResponse(httpResponse, cancellationToken); + Result result = await this.HandleResponseX(httpResponse, cancellationToken); + + if (result.IsFailed) + return ResultHelpers.CreateFailure(result); + + // call was successful so now deserialise the body to the response object + ResponseData responseData = this.HandleResponseContent(result.Data); + + return Result.Success(responseData.Data); } catch(Exception ex){ // An exception has occurred, add some additional information to the message @@ -403,7 +488,16 @@ public async Task>> GetMerchants(String accessToken, Guid HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(request, cancellationToken); // Process the response - return await ProcessResponse>(httpResponse, cancellationToken); + // Process the response + Result result = await this.HandleResponseX(httpResponse, cancellationToken); + + if (result.IsFailed) + return ResultHelpers.CreateFailure(result); + + // call was successful so now deserialise the body to the response object + ResponseData> responseData = this.HandleResponseContent>(result.Data); + + return Result.Success(responseData.Data); } catch(Exception ex){ // An exception has occurred, add some additional information to the message @@ -426,7 +520,15 @@ public async Task>> GetOperators(String accessToken, Guid HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(request, cancellationToken); // Process the response - return await ProcessResponse>(httpResponse, cancellationToken); + Result result = await this.HandleResponseX(httpResponse, cancellationToken); + + if (result.IsFailed) + return ResultHelpers.CreateFailure(result); + + // call was successful so now deserialise the body to the response object + ResponseData> responseData = this.HandleResponseContent>(result.Data); + + return Result.Success(responseData.Data); } catch(Exception ex){ // An exception has occurred, add some additional information to the message @@ -454,7 +556,15 @@ public async Task> GetTodaysFailedSales(String accessToken, HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(request, cancellationToken); // Process the response - return await ProcessResponse(httpResponse, cancellationToken); + Result result = await this.HandleResponseX(httpResponse, cancellationToken); + + if (result.IsFailed) + return ResultHelpers.CreateFailure(result); + + // call was successful so now deserialise the body to the response object + ResponseData responseData = this.HandleResponseContent(result.Data); + + return Result.Success(responseData.Data); } catch (Exception ex) { // An exception has occurred, add some additional information to the message @@ -481,7 +591,15 @@ public async Task> GetTodaysSales(String accessToken, Guid e HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(request, cancellationToken); // Process the response - return await ProcessResponse(httpResponse, cancellationToken); + Result result = await this.HandleResponseX(httpResponse, cancellationToken); + + if (result.IsFailed) + return ResultHelpers.CreateFailure(result); + + // call was successful so now deserialise the body to the response object + ResponseData responseData = this.HandleResponseContent(result.Data); + + return Result.Success(responseData.Data); } catch(Exception ex){ // An exception has occurred, add some additional information to the message @@ -508,7 +626,15 @@ public async Task>> GetTodaysSalesCountByHou HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(request, cancellationToken); // Process the response - return await ProcessResponse>(httpResponse, cancellationToken); + Result result = await this.HandleResponseX(httpResponse, cancellationToken); + + if (result.IsFailed) + return ResultHelpers.CreateFailure(result); + + // call was successful so now deserialise the body to the response object + ResponseData> responseData = this.HandleResponseContent>(result.Data); + + return Result.Success(responseData.Data); } catch(Exception ex){ // An exception has occurred, add some additional information to the message @@ -535,7 +661,15 @@ public async Task>> GetTodaysSalesValueByHou HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(request, cancellationToken); // Process the response - return await ProcessResponse>(httpResponse, cancellationToken); + Result result = await this.HandleResponseX(httpResponse, cancellationToken); + + if (result.IsFailed) + return ResultHelpers.CreateFailure(result); + + // call was successful so now deserialise the body to the response object + ResponseData> responseData = this.HandleResponseContent>(result.Data); + + return Result.Success(responseData.Data); } catch(Exception ex){ // An exception has occurred, add some additional information to the message @@ -562,7 +696,15 @@ public async Task> GetTodaysSettlement(String accessTok HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(request, cancellationToken); // Process the response - return await ProcessResponse(httpResponse, cancellationToken); + Result result = await this.HandleResponseX(httpResponse, cancellationToken); + + if (result.IsFailed) + return ResultHelpers.CreateFailure(result); + + // call was successful so now deserialise the body to the response object + ResponseData responseData = this.HandleResponseContent(result.Data); + + return Result.Success(responseData.Data); } catch(Exception ex){ // An exception has occurred, add some additional information to the message @@ -584,7 +726,15 @@ public async Task>> GetTopBottomMerchantData( HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(request, cancellationToken); // Process the response - return await ProcessResponse>(httpResponse, cancellationToken); + Result result = await this.HandleResponseX(httpResponse, cancellationToken); + + if (result.IsFailed) + return ResultHelpers.CreateFailure(result); + + // call was successful so now deserialise the body to the response object + ResponseData> responseData = this.HandleResponseContent>(result.Data); + + return Result.Success(responseData.Data); } catch(Exception ex){ // An exception has occurred, add some additional information to the message @@ -606,7 +756,15 @@ public async Task>> GetTopBottomOperatorData( HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(request, cancellationToken); // Process the response - return await ProcessResponse>(httpResponse, cancellationToken); + Result result = await this.HandleResponseX(httpResponse, cancellationToken); + + if (result.IsFailed) + return ResultHelpers.CreateFailure(result); + + // call was successful so now deserialise the body to the response object + ResponseData> responseData = this.HandleResponseContent>(result.Data); + + return Result.Success(responseData.Data); } catch(Exception ex){ // An exception has occurred, add some additional information to the message @@ -628,7 +786,15 @@ public async Task>> GetTopBottomProductData(St HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(request, cancellationToken); // Process the response - return await ProcessResponse>(httpResponse, cancellationToken); + Result result = await this.HandleResponseX(httpResponse, cancellationToken); + + if (result.IsFailed) + return ResultHelpers.CreateFailure(result); + + // call was successful so now deserialise the body to the response object + ResponseData> responseData = this.HandleResponseContent>(result.Data); + + return Result.Success(responseData.Data); } catch(Exception ex){ // An exception has occurred, add some additional information to the message