Skip to content

Commit c71fa69

Browse files
Merge pull request #140 from StuartFerguson/task/#139_addgetcontracttoclient
Added GetContract method to client
2 parents 49cb7d8 + b0b8ca2 commit c71fa69

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

EstateManagement.Client/EstateClient.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,52 @@ public async Task<List<ContractResponse>> GetContracts(String accessToken,
607607
return response;
608608
}
609609

610+
/// <summary>
611+
/// Gets the contracts.
612+
/// </summary>
613+
/// <param name="accessToken">The access token.</param>
614+
/// <param name="estateId">The estate identifier.</param>
615+
/// <param name="contractId">The contract identifier.</param>
616+
/// <param name="includeProducts"></param>
617+
/// <param name="includeProductsWithFees"></param>
618+
/// <param name="cancellationToken">The cancellation token.</param>
619+
/// <returns></returns>
620+
public async Task<ContractResponse> GetContract(String accessToken,
621+
Guid estateId,
622+
Guid contractId,
623+
Boolean includeProducts,
624+
Boolean includeProductsWithFees,
625+
CancellationToken cancellationToken)
626+
{
627+
ContractResponse response = null;
628+
629+
String requestUri = this.BuildRequestUrl($"/api/estates/{estateId}/contracts/{contractId}?includeProducts={includeProducts}&includeProductsWithFees={includeProductsWithFees}");
630+
631+
try
632+
{
633+
// Add the access token to the client headers
634+
this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
635+
636+
// Make the Http Call here
637+
HttpResponseMessage httpResponse = await this.HttpClient.GetAsync(requestUri, cancellationToken);
638+
639+
// Process the response
640+
String content = await this.HandleResponse(httpResponse, cancellationToken);
641+
642+
// call was successful so now deserialise the body to the response object
643+
response = JsonConvert.DeserializeObject<ContractResponse>(content);
644+
}
645+
catch (Exception ex)
646+
{
647+
// An exception has occurred, add some additional information to the message
648+
Exception exception = new Exception($"Error getting contract {contractId} for estate {estateId}.", ex);
649+
650+
throw exception;
651+
}
652+
653+
return response;
654+
}
655+
610656
/// <summary>
611657
/// Gets the estate.
612658
/// </summary>

EstateManagement.Client/IEstateClient.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,21 @@ Task<List<ContractResponse>> GetContracts(String accessToken,
183183
Guid estateId,
184184
CancellationToken cancellationToken);
185185

186+
/// <summary>
187+
/// Gets the contract.
188+
/// </summary>
189+
/// <param name="accessToken">The access token.</param>
190+
/// <param name="estateId">The estate identifier.</param>
191+
/// <param name="contractId">The contract identifier.</param>
192+
/// <param name="cancellationToken">The cancellation token.</param>
193+
/// <returns></returns>
194+
Task<ContractResponse> GetContract(String accessToken,
195+
Guid estateId,
196+
Guid contractId,
197+
Boolean includeProducts,
198+
Boolean includeProductsWithFees,
199+
CancellationToken cancellationToken);
200+
186201
/// <summary>
187202
/// Gets the estate.
188203
/// </summary>

0 commit comments

Comments
 (0)