diff --git a/src/FlightRecorder.Mvc/Api/ReportsClient.cs b/src/FlightRecorder.Mvc/Api/ReportsClient.cs index 154a67b..bbc2f5c 100644 --- a/src/FlightRecorder.Mvc/Api/ReportsClient.cs +++ b/src/FlightRecorder.Mvc/Api/ReportsClient.cs @@ -1,14 +1,8 @@ using FlightRecorder.Mvc.Configuration; using FlightRecorder.Mvc.Entities; using FlightRecorder.Mvc.Interfaces; -using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Options; using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http; -using System.Threading.Tasks; namespace FlightRecorder.Mvc.Api { @@ -19,6 +13,22 @@ public ReportsClient(HttpClient client, IOptions settings, IHttpCon { } + /// + /// Return the sighting statistics report + /// + /// + public async Task SightingStatisticsAsync() + { + // Construct the route + string route = Settings.Value.ApiRoutes.First(r => r.Name == "SightingStatistics").Route; + + // Call the endpoint and decode the response + string json = await SendDirectAsync(route, null, HttpMethod.Get); + var records = JsonConvert.DeserializeObject(json, JsonSettings); + + return records; + } + /// /// Return the airline statistics report /// diff --git a/src/FlightRecorder.Mvc/Controllers/SightingStatisticsController.cs b/src/FlightRecorder.Mvc/Controllers/SightingStatisticsController.cs new file mode 100644 index 0000000..fb18c44 --- /dev/null +++ b/src/FlightRecorder.Mvc/Controllers/SightingStatisticsController.cs @@ -0,0 +1,34 @@ +using FlightRecorder.Mvc.Api; +using FlightRecorder.Mvc.Configuration; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Options; + +namespace FlightRecorder.Mvc.Controllers +{ + [Authorize] + public class SightingStatisticsController : Controller + { + private readonly ReportsClient _reportsClient; + private readonly IOptions _settings; + + public SightingStatisticsController( + ReportsClient reportsClient, + IOptions settings) + { + _reportsClient = reportsClient; + _settings = settings; + } + + /// + /// Retrieve and serve the report + /// + /// + [HttpGet] + public async Task Index() + { + var report = await _reportsClient.SightingStatisticsAsync(); + return View(report); + } + } +} diff --git a/src/FlightRecorder.Mvc/Entities/SightingStatistics.cs b/src/FlightRecorder.Mvc/Entities/SightingStatistics.cs new file mode 100644 index 0000000..538b772 --- /dev/null +++ b/src/FlightRecorder.Mvc/Entities/SightingStatistics.cs @@ -0,0 +1,13 @@ +namespace FlightRecorder.Mvc.Entities +{ + public record SightingStatistics + ( + int Aircraft, + int Manufacturers, + int Models, + int Airlines, + int Flights, + int Sightings, + int Locations + ); +} diff --git a/src/FlightRecorder.Mvc/Views/Shared/_Layout.cshtml b/src/FlightRecorder.Mvc/Views/Shared/_Layout.cshtml index 13d01a8..10d9bc0 100644 --- a/src/FlightRecorder.Mvc/Views/Shared/_Layout.cshtml +++ b/src/FlightRecorder.Mvc/Views/Shared/_Layout.cshtml @@ -48,6 +48,7 @@ Reports