Skip to content

Commit

Permalink
Added sighting statistics report to the UI
Browse files Browse the repository at this point in the history
  • Loading branch information
davewalker5 committed Aug 13, 2024
1 parent e65760e commit 3715767
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/FlightRecorder.Mvc/Api/ReportsClient.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -19,6 +13,22 @@ public ReportsClient(HttpClient client, IOptions<AppSettings> settings, IHttpCon
{
}

/// <summary>
/// Return the sighting statistics report
/// </summary>
/// <returns></returns>
public async Task<SightingStatistics> 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<SightingStatistics>(json, JsonSettings);

return records;
}

/// <summary>
/// Return the airline statistics report
/// </summary>
Expand Down
34 changes: 34 additions & 0 deletions src/FlightRecorder.Mvc/Controllers/SightingStatisticsController.cs
Original file line number Diff line number Diff line change
@@ -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<AppSettings> _settings;

public SightingStatisticsController(
ReportsClient reportsClient,
IOptions<AppSettings> settings)
{
_reportsClient = reportsClient;
_settings = settings;
}

/// <summary>
/// Retrieve and serve the report
/// </summary>
/// <returns></returns>
[HttpGet]
public async Task<IActionResult> Index()
{
var report = await _reportsClient.SightingStatisticsAsync();
return View(report);
}
}
}
13 changes: 13 additions & 0 deletions src/FlightRecorder.Mvc/Entities/SightingStatistics.cs
Original file line number Diff line number Diff line change
@@ -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
);
}
1 change: 1 addition & 0 deletions src/FlightRecorder.Mvc/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
Reports
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" asp-area="" asp-controller="SightingStatistics" asp-action="Index">Sighting Statistics</a>
<a class="dropdown-item" asp-area="" asp-controller="AirlineStatistics" asp-action="Index">Airline Statistics</a>
<a class="dropdown-item" asp-area="" asp-controller="FlightsByMonth" asp-action="Index">Flights By Month</a>
<a class="dropdown-item" asp-area="" asp-controller="LocationStatistics" asp-action="Index">Location Statistics</a>
Expand Down
50 changes: 50 additions & 0 deletions src/FlightRecorder.Mvc/Views/SightingStatistics/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
@model FlightRecorder.Mvc.Entities.SightingStatistics

@{
ViewData["Title"] = "Sighting Statistics Report";
}

<p class="text-center font-weight-bold">
<span style="font-size: 1.2rem">
Sighting Statistics
</span>
<br />
<small class="text-muted">
<em>
Produce summary statistics for all sightings
</em>
</small>
</p>

<div class="container-fluid">
<table class="table">
<tr>
<th>Aircraft</th>
<td>@Model.Aircraft</td>
</tr>
<tr>
<th>Models</th>
<td>@Model.Models</td>
</tr>
<tr>
<th>Manufacturers</th>
<td>@Model.Manufacturers</td>
</tr>
<tr>
<th>Airlines</th>
<td>@Model.Airlines</td>
</tr>
<tr>
<th>Flights</th>
<td>@Model.Flights</td>
</tr>
<tr>
<th>Sightings</th>
<td>@Model.Sightings</td>
</tr>
<tr>
<th>Locations</th>
<td>@Model.Locations</td>
</tr>
</table>
</div>
4 changes: 4 additions & 0 deletions src/FlightRecorder.Mvc/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
"Name": "Sightings",
"Route": "/sightings"
},
{
"Name": "SightingStatistics",
"Route": "/reports/sightings"
},
{
"Name": "AirlineStatistics",
"Route": "/reports/airlines"
Expand Down

0 comments on commit 3715767

Please sign in to comment.