Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions EstateReportingAPI.Client/EstateReportingAPI.Client.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0;netstandard2.1</TargetFrameworks>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);IncludeP2PAssets</TargetsForTfmSpecificBuildOutput>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ClientProxyBase" Version="2023.8.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\EstateReportingAPI.DataTrasferObjects\EstateReportingAPI.DataTransferObjects.csproj" PrivateAssets="All" />
</ItemGroup>

<Target Name="IncludeP2PAssets">
<ItemGroup>
<BuildOutputInPackage Include="$(OutputPath)EstateManagement.DataTransferObjects.dll" />
</ItemGroup>
</Target>

</Project>
247 changes: 247 additions & 0 deletions EstateReportingAPI.Client/EstateReportingApiClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
namespace EstateReportingAPI.Client{
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
using ClientProxyBase;
using DataTransferObjects;
using DataTrasferObjects;
using Newtonsoft.Json;

public class EstateReportingApiClient : ClientProxyBase, IEstateReportingApiClient{
#region Fields

private readonly Func<String, String> BaseAddressResolver;

#endregion

#region Constructors

public EstateReportingApiClient(Func<String, String> baseAddressResolver,
HttpClient httpClient) : base(httpClient){
this.BaseAddressResolver = baseAddressResolver;

// Add the API version header
this.HttpClient.DefaultRequestHeaders.Add("api-version", "1.0");
}

#endregion

#region Methods

public async Task<List<CalendarDate>> GetCalendarDates(String accessToken, Guid estateId, Int32 year, CancellationToken cancellationToken){
List<CalendarDate> response = null;

String requestUri = this.BuildRequestUrl($"/api/dimensions/calendar/{year}/dates");

try{
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUri);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
request.Headers.Add("EstateId", estateId.ToString());

// Make the Http Call here
HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(request, cancellationToken);

// Process the response
String content = await this.HandleResponse(httpResponse, cancellationToken);

// call was successful so now deserialise the body to the response object
response = JsonConvert.DeserializeObject<List<CalendarDate>>(content);
}
catch(Exception ex){
// An exception has occurred, add some additional information to the message
Exception exception = new Exception($"Error getting calendar dates for year {year} for estate {{estateId}}.", ex);

throw exception;
}

return response;
}

public async Task<List<CalendarYear>> GetCalendarYears(String accessToken, Guid estateId, CancellationToken cancellationToken){
List<CalendarYear> response = null;

String requestUri = this.BuildRequestUrl("/api/dimensions/calendar/years");

try{
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUri);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
request.Headers.Add("EstateId", estateId.ToString());

// Make the Http Call here
HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(request, cancellationToken);

// Process the response
String content = await this.HandleResponse(httpResponse, cancellationToken);

// call was successful so now deserialise the body to the response object
response = JsonConvert.DeserializeObject<List<CalendarYear>>(content);
}
catch(Exception ex){
// An exception has occurred, add some additional information to the message
Exception exception = new Exception("Error getting calendar years for estate {estateId}.", ex);

throw exception;
}

return response;
}

public async Task<List<ComparisonDate>> GetComparisonDates(String accessToken, Guid estateId, Int32 year, CancellationToken cancellationToken){
List<ComparisonDate> response = null;

String requestUri = this.BuildRequestUrl("/api/dimensions/calendar/calendar/comparisondates");

try{
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUri);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
request.Headers.Add("EstateId", estateId.ToString());

// Make the Http Call here
HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(request, cancellationToken);

// Process the response
String content = await this.HandleResponse(httpResponse, cancellationToken);

// call was successful so now deserialise the body to the response object
response = JsonConvert.DeserializeObject<List<ComparisonDate>>(content);
}
catch(Exception ex){
// An exception has occurred, add some additional information to the message
Exception exception = new Exception("Error getting comparison dates for estate {estateId}.", ex);

throw exception;
}

return response;
}

public async Task<TodaysSales> GetTodaysSales(String accessToken, Guid estateId, DateTime comparisonDate, CancellationToken cancellationToken){
TodaysSales response = null;

String requestUri = this.BuildRequestUrl($"/api/facts/transactions/todayssales?comparisonDate={comparisonDate.Date:yyyy-MM-dd}");

try{
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUri);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
request.Headers.Add("EstateId", estateId.ToString());

// Make the Http Call here
HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(request, cancellationToken);

// Process the response
String content = await this.HandleResponse(httpResponse, cancellationToken);

// call was successful so now deserialise the body to the response object
response = JsonConvert.DeserializeObject<TodaysSales>(content);
}
catch(Exception ex){
// An exception has occurred, add some additional information to the message
Exception exception = new Exception("Error getting todays sales for estate {estateId}.", ex);

throw exception;
}

return response;
}

public async Task<List<TodaysSalesCountByHour>> GetTodaysSalesCountByHour(String accessToken, Guid estateId, DateTime comparisonDate, CancellationToken cancellationToken){
List<TodaysSalesCountByHour> response = null;

String requestUri = this.BuildRequestUrl($"/api/facts/transactions/todayssales/countbyhour?comparisonDate={comparisonDate.Date:yyyy-MM-dd}");

try{
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUri);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
request.Headers.Add("EstateId", estateId.ToString());

// Make the Http Call here
HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(request, cancellationToken);

// Process the response
String content = await this.HandleResponse(httpResponse, cancellationToken);

// call was successful so now deserialise the body to the response object
response = JsonConvert.DeserializeObject<List<TodaysSalesCountByHour>>(content);
}
catch(Exception ex){
// An exception has occurred, add some additional information to the message
Exception exception = new Exception("Error getting todays sales count by hour for estate {estateId}.", ex);

throw exception;
}

return response;
}

public async Task<List<TodaysSalesValueByHour>> GetTodaysSalesValueByHour(String accessToken, Guid estateId, DateTime comparisonDate, CancellationToken cancellationToken){
List<TodaysSalesValueByHour> response = null;

String requestUri = this.BuildRequestUrl($"/api/facts/transactions/todayssales/valuebyhour?comparisonDate={comparisonDate.Date:yyyy-MM-dd}");

try{
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUri);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
request.Headers.Add("EstateId", estateId.ToString());

// Make the Http Call here
HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(request, cancellationToken);

// Process the response
String content = await this.HandleResponse(httpResponse, cancellationToken);

// call was successful so now deserialise the body to the response object
response = JsonConvert.DeserializeObject<List<TodaysSalesValueByHour>>(content);
}
catch(Exception ex){
// An exception has occurred, add some additional information to the message
Exception exception = new Exception("Error getting todays sales value by hour for estate {estateId}.", ex);

throw exception;
}

return response;
}

public async Task<TodaysSettlement> GetTodaysSettlement(String accessToken, Guid estateId, DateTime comparisonDate, CancellationToken cancellationToken){
TodaysSettlement response = null;

String requestUri = this.BuildRequestUrl($"/api/facts/settlements/todayssettlement?comparisonDate={comparisonDate.Date:yyyy-MM-dd}");

try{
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUri);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
request.Headers.Add("EstateId", estateId.ToString());

// Make the Http Call here
HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(request, cancellationToken);

// Process the response
String content = await this.HandleResponse(httpResponse, cancellationToken);

// call was successful so now deserialise the body to the response object
response = JsonConvert.DeserializeObject<TodaysSettlement>(content);
}
catch(Exception ex){
// An exception has occurred, add some additional information to the message
Exception exception = new Exception("Error getting todays settlement for estate {estateId}.", ex);

throw exception;
}

return response;
}

private String BuildRequestUrl(String route){
String baseAddress = this.BaseAddressResolver("EstateReportingApi");

String requestUri = $"{baseAddress}{route}";

return requestUri;
}

#endregion
}
}
22 changes: 22 additions & 0 deletions EstateReportingAPI.Client/IEstateReportingApiClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace EstateReportingAPI.Client{
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using DataTransferObjects;
using DataTrasferObjects;

public interface IEstateReportingApiClient{
#region Methods

Task<List<CalendarDate>> GetCalendarDates(String accessToken, Guid estateId, Int32 year, CancellationToken cancellationToken);
Task<List<CalendarYear>> GetCalendarYears(String accessToken, Guid estateId, CancellationToken cancellationToken);
Task<List<ComparisonDate>> GetComparisonDates(String accessToken, Guid estateId, Int32 year, CancellationToken cancellationToken);
Task<TodaysSales> GetTodaysSales(String accessToken, Guid estateId, DateTime comparisonDate, CancellationToken cancellationToken);
Task<List<TodaysSalesCountByHour>> GetTodaysSalesCountByHour(String accessToken, Guid estateId, DateTime comparisonDate, CancellationToken cancellationToken);
Task<List<TodaysSalesValueByHour>> GetTodaysSalesValueByHour(String accessToken, Guid estateId, DateTime comparisonDate, CancellationToken cancellationToken);
Task<TodaysSettlement> GetTodaysSettlement(String accessToken, Guid estateId, DateTime comparisonDate, CancellationToken cancellationToken);

#endregion
}
}
18 changes: 18 additions & 0 deletions EstateReportingAPI.DataTrasferObjects/CalendarDate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace EstateReportingAPI.DataTrasferObjects{
using System;

public class CalendarDate
{
public DateTime Date { get; set; }
public String DayOfWeek{ get; set; }
public Int32 DayOfWeekNumber{ get; set; }
public String DayOfWeekShort{ get; set; }
public String MonthName{ get; set; }
public String MonthNameShort { get; set; }
public Int32 MonthNumber { get; set; }
public Int32 WeekNumber { get; set; }
public String WeekNumberString { get; set; }
public Int32 Year { get; set; }
public String YearWeekNumber { get; set; }
}
}
22 changes: 0 additions & 22 deletions EstateReportingAPI.DataTrasferObjects/CalendarYear.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,4 @@ public class CalendarYear
{
public Int32 Year{ get; set; }
}

public class ComparisonDate{
public Int32 OrderValue{ get; set; }
public DateTime Date { get; set; }
public String Description { get; set; }

}

public class CalendarDate
{
public DateTime Date { get; set; }
public String DayOfWeek{ get; set; }
public Int32 DayOfWeekNumber{ get; set; }
public String DayOfWeekShort{ get; set; }
public String MonthName{ get; set; }
public String MonthNameShort { get; set; }
public Int32 MonthNumber { get; set; }
public Int32 WeekNumber { get; set; }
public String WeekNumberString { get; set; }
public Int32 Year { get; set; }
public String YearWeekNumber { get; set; }
}
}
10 changes: 10 additions & 0 deletions EstateReportingAPI.DataTrasferObjects/ComparisonDate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace EstateReportingAPI.DataTrasferObjects{
using System;

public class ComparisonDate{
public Int32 OrderValue{ get; set; }
public DateTime Date { get; set; }
public String Description { get; set; }

}
}
14 changes: 14 additions & 0 deletions EstateReportingAPI.DataTrasferObjects/TodaysSales.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace EstateReportingAPI.DataTransferObjects
{
public class TodaysSales
{
public Decimal TodaysSalesValue { get; set; }
public Int32 TodaysSalesCount { get; set; }
public Decimal ComparisonSalesValue { get; set; }
public Int32 ComparisonSalesCount { get; set; }
}
}
11 changes: 11 additions & 0 deletions EstateReportingAPI.DataTrasferObjects/TodaysSalesCountByHour.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace EstateReportingAPI.DataTransferObjects{
using System;

public class TodaysSalesCountByHour
{
public Int32 Hour { get; set; }
public Int32 TodaysSalesCount { get; set; }
public Decimal ComparisonSalesValue { get; set; }
public Int32 ComparisonSalesCount { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace EstateReportingAPI.DataTransferObjects{
using System;

public class TodaysSalesValueByHour{
public Int32 Hour{ get; set; }
public Decimal TodaysSalesValue { get; set; }
public Decimal ComparisonSalesValue { get; set; }
}
}
Loading