120 lines
5.3 KiB
C#
120 lines
5.3 KiB
C#
using ReserveManagementSystemLib.Configuration;
|
|
using LCU.Library.Internal.ApiSecurity.Models;
|
|
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.IndirectLoan;
|
|
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.CoreRequests;
|
|
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Transaction;
|
|
using LCU.Library.Internal.LcuHttpClient.HttpRequest;
|
|
using LCU.Library.Internal.ApiSecurity.Enums;
|
|
using LCU.Library.Internal.LcuHttpClient.Utilities;
|
|
|
|
namespace ReserveManagementSystemApi.ServiceClients
|
|
{
|
|
public class CoreApiServiceClient : ICoreApiServiceClient
|
|
{
|
|
private readonly ApiSecurityConfiguration _apiSecurityConfiguration;
|
|
private readonly CoreApiConfiguration _coreApiWrapperConfiguration;
|
|
private readonly IPostRequest _postRequest;
|
|
private readonly IGetRequest _getRequest;
|
|
private readonly IPutRequest _putRequest;
|
|
|
|
private const string ClientKeyValue = "ReserveManagementSystem";
|
|
|
|
public CoreApiServiceClient(
|
|
ApiSecurityConfiguration apiSecurityConfiguration,
|
|
CoreApiConfiguration coreApiWrapperConfiguration,
|
|
IGetRequest getRequest,
|
|
IPostRequest postRequest,
|
|
IPutRequest putRequest
|
|
)
|
|
{
|
|
_apiSecurityConfiguration = apiSecurityConfiguration;
|
|
_coreApiWrapperConfiguration = coreApiWrapperConfiguration;
|
|
_getRequest = getRequest;
|
|
_postRequest = postRequest;
|
|
_putRequest = putRequest;
|
|
}
|
|
|
|
public async Task<List<MonetaryTransactionResponse>> PostMonetaryTransactions(List<GroupedMonetaryTransactionRequest> loanReserves)
|
|
{
|
|
try
|
|
{
|
|
var path = $"{_coreApiWrapperConfiguration.BaseUrl}{_coreApiWrapperConfiguration.PostMonetaryTransactions}";
|
|
var uri = new Uri(path);
|
|
var response = await _postRequest.Async<List<GroupedMonetaryTransactionRequest>, List<MonetaryTransactionResponse>>(uri, loanReserves,
|
|
HttpUtilities.GetApiKeyHeaders(ClientKeyValue, _apiSecurityConfiguration.ExtractApiKey(ClientKeyValue, ApiKeySetName.InternalKeySet)),
|
|
0, Convert.ToInt16(_coreApiWrapperConfiguration.ApiTimeOutInSeconds));
|
|
return response;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error(ex, "Error in posting MonetaryTransactions.");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task<List<UpdateDealerOriginalBalanceResponse>> PutDealerOriginalBalance(string accountNumber)
|
|
{
|
|
try
|
|
{
|
|
var path = $"{_coreApiWrapperConfiguration.BaseUrl}{_coreApiWrapperConfiguration.PutDealerOriginalBalance}";
|
|
var uri = new Uri(path);
|
|
var response = await _putRequest.Async<string, List<UpdateDealerOriginalBalanceResponse>>(uri, accountNumber,
|
|
HttpUtilities.GetApiKeyHeaders(ClientKeyValue, _apiSecurityConfiguration.ExtractApiKey(ClientKeyValue, ApiKeySetName.InternalKeySet)),
|
|
0, Convert.ToUInt16(_coreApiWrapperConfiguration.ApiTimeOutInSeconds));
|
|
return response;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error(ex, "Error updating Dealer Original Balance");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task<List<IndirectLoanDetail>> GetIndirectLoansByPostedDate(string afterPostDate)
|
|
{
|
|
try
|
|
{
|
|
var path = $"{_coreApiWrapperConfiguration.BaseUrl}{_coreApiWrapperConfiguration.GetIndirectLoansByPostedDate}{afterPostDate}";
|
|
var response = await _getRequest.AsyncWithNewton<List<IndirectLoanDetail>>(path, null, 0, Convert.ToUInt16(_coreApiWrapperConfiguration.ApiTimeOutInSeconds));
|
|
return response;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error(ex, "Error getting Indirect Loans By Posted Date");
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public async Task<List<ClosedIndirectLoan>> GetClosedLoansByPostedDate(string afterPostDate)
|
|
{
|
|
try
|
|
{
|
|
var path = $"{_coreApiWrapperConfiguration.BaseUrl}{_coreApiWrapperConfiguration.GetClosedLoansByPostedDate}{afterPostDate}";
|
|
var response = await _getRequest.AsyncWithNewton<List<ClosedIndirectLoan>>(path);
|
|
return response;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error(ex, "Error getting Closed Loans By Posted Date");
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public async Task<List<IndirectLoanDetail>> GetClosedLoansWithDetailByClosedDate(string afterClosedDate)
|
|
{
|
|
try
|
|
{
|
|
var path = $"{_coreApiWrapperConfiguration.BaseUrl}{_coreApiWrapperConfiguration.GetClosedIndirectLoansWithDetailByPostedDate}{afterClosedDate}";
|
|
var response = await _getRequest.AsyncWithNewton<List<IndirectLoanDetail>>(path);
|
|
return response;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error(ex, "Error getting Closed Loans With Detail");
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|
|
} |