Skip to content

Commit

Permalink
Added sighting statistics report to the API
Browse files Browse the repository at this point in the history
  • Loading branch information
davewalker5 committed Aug 13, 2024
1 parent 44a9196 commit b664ba3
Show file tree
Hide file tree
Showing 19 changed files with 112 additions and 16 deletions.
36 changes: 30 additions & 6 deletions src/FlightRecorder.Api/Controllers/ReportsController.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
using FlightRecorder.BusinessLogic.Factory;
using FlightRecorder.Api.Entities;
using FlightRecorder.BusinessLogic.Factory;
using FlightRecorder.Entities.Db;
using FlightRecorder.Entities.Reporting;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using System.Web;

namespace FlightRecorder.Api.Controllers
Expand All @@ -27,6 +23,34 @@ public ReportsController(FlightRecorderFactory factory)
_factory = factory;
}

/// <summary>
/// Generate the sighting statistics report
/// </summary>
/// <returns></returns>
[HttpGet]
[Route("sightings")]
public async Task<ActionResult<SightingStatisticsReport>> GetSightingStatistics()
{
var aircraft = await _factory.Aircraft.CountAsync();
var manufacturers = await _factory.Manufacturers.CountAsync();
var models = await _factory.Models.CountAsync();
var airlines = await _factory.Airlines.CountAsync();
var flights = await _factory.Flights.CountAsync();
var sightings = await _factory.Sightings.CountAsync();
var locations = await _factory.Locations.CountAsync();

return new SightingStatisticsReport
(
aircraft,
manufacturers,
models,
airlines,
flights,
sightings,
locations
);
}

/// <summary>
/// Generate the airline statistics report
/// </summary>
Expand Down
16 changes: 16 additions & 0 deletions src/FlightRecorder.Api/Entities/SightingStatisticsReport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Diagnostics.CodeAnalysis;

namespace FlightRecorder.Api.Entities
{
[ExcludeFromCodeCoverage]
public record SightingStatisticsReport
(
int Aircraft,
int Manufacturers,
int Models,
int Airlines,
int Flights,
int Sightings,
int Locations
);
}
6 changes: 3 additions & 3 deletions src/FlightRecorder.Api/FlightRecorder.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ReleaseVersion>1.10.0.0</ReleaseVersion>
<FileVersion>1.10.0.0</FileVersion>
<ProductVersion>1.10.0</ProductVersion>
<ReleaseVersion>1.11.0.0</ReleaseVersion>
<FileVersion>1.11.0.0</FileVersion>
<ProductVersion>1.11.0</ProductVersion>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
7 changes: 7 additions & 0 deletions src/FlightRecorder.BusinessLogic/Database/AircraftManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ public IAsyncEnumerable<Aircraft> ListAsync(Expression<Func<Aircraft, bool>> pre
return aircraft;
}

/// <summary>
/// Return the number of aircraft in the database
/// </summary>
/// <returns></returns>
public async Task<int> CountAsync()
=> await _factory.Context.Aircraft.CountAsync();

/// <summary>
/// Get the aircraft of a specified model
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions src/FlightRecorder.BusinessLogic/Database/AirlineManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ public IAsyncEnumerable<Airline> ListAsync(Expression<Func<Airline, bool>> predi
return results;
}

/// <summary>
/// Return the number of airlines in the database
/// </summary>
/// <returns></returns>
public async Task<int> CountAsync()
=> await _context.Airlines.CountAsync();

/// <summary>
/// Add a named airline, if it doesn't already exist
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions src/FlightRecorder.BusinessLogic/Database/FlightManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ public IAsyncEnumerable<Flight> ListAsync(Expression<Func<Flight, bool>> predica
return flights;
}

/// <summary>
/// Return the number of flights in the database
/// </summary>
/// <returns></returns>
public async Task<int> CountAsync()
=> await _factory.Context.Flights.CountAsync();

/// <summary>
/// Get the flights for a named airline
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions src/FlightRecorder.BusinessLogic/Database/LocationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ public virtual IAsyncEnumerable<Location> ListAsync(Expression<Func<Location, bo
return results;
}

/// <summary>
/// Return the number of locations in the database
/// </summary>
/// <returns></returns>
public async Task<int> CountAsync()
=> await _context.Locations.CountAsync();

/// <summary>
/// Add a named location, if it doesn't already exist
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ public IAsyncEnumerable<Manufacturer> ListAsync(Expression<Func<Manufacturer, bo
return results;
}

/// <summary>
/// Return the number of manufacturers in the database
/// </summary>
/// <returns></returns>
public async Task<int> CountAsync()
=> await _context.Manufacturers.CountAsync();

/// <summary>
/// Add a named manufacturer, if it doesn't already exist
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions src/FlightRecorder.BusinessLogic/Database/ModelManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ public IAsyncEnumerable<Model> ListAsync(Expression<Func<Model, bool>> predicate
return models;
}

/// <summary>
/// Return the number of aircraft models in the database
/// </summary>
/// <returns></returns>
public async Task<int> CountAsync()
=> await _factory.Context.Models.CountAsync();

/// <summary>
/// Get the models for a named manufacturer
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions src/FlightRecorder.BusinessLogic/Database/SightingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ public IAsyncEnumerable<Sighting> ListAsync(Expression<Func<Sighting, bool>> pre
return sightings;
}

/// <summary>
/// Return the number of sightings in the database
/// </summary>
/// <returns></returns>
public async Task<int> CountAsync()
=> await _factory.Context.Sightings.CountAsync();

/// <summary>
/// Add a new sighting
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/FlightRecorder.Entities/Interfaces/IAircraftManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public interface IAircraftManager
Task<Aircraft> AddAsync(string registration, string serialNumber, long? yearOfManufacture, string modelName, string manufacturerName);
Task<Aircraft> GetAsync(Expression<Func<Aircraft, bool>> predicate);
IAsyncEnumerable<Aircraft> ListAsync(Expression<Func<Aircraft, bool>> predicate, int pageNumber, int pageSize);
Task<int> CountAsync();
Task<IAsyncEnumerable<Aircraft>> ListByModelAsync(string modelName, int pageNumber, int pageSize);
Task<IAsyncEnumerable<Aircraft>> ListByManufacturerAsync(string manufacturerName, int pageNumber, int pageSize);
}
Expand Down
3 changes: 2 additions & 1 deletion src/FlightRecorder.Entities/Interfaces/IAirlineManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public interface IAirlineManager
{
Task<Airline> AddAsync(string name);
Task<Airline> GetAsync(Expression<Func<Airline, bool>> predicate);
IAsyncEnumerable<Airline> ListAsync(Expression<Func<Airline, bool>> predicate, int pageNumber, int pageSize);
IAsyncEnumerable<Airline> ListAsync(Expression<Func<Airline, bool>> predicate, int pageNumber, int pageSize);
Task<int> CountAsync();
}
}
1 change: 1 addition & 0 deletions src/FlightRecorder.Entities/Interfaces/IFlightManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public interface IFlightManager
Task<Flight> AddAsync(string number, string embarkation, string destination, string airlineName);
Task<Flight> GetAsync(Expression<Func<Flight, bool>> predicate);
IAsyncEnumerable<Flight> ListAsync(Expression<Func<Flight, bool>> predicate, int pageNumber, int pageSize);
Task<int> CountAsync();
Task<IAsyncEnumerable<Flight>> ListByAirlineAsync(string airlineName, int pageNumber, int pageSize);
}
}
3 changes: 2 additions & 1 deletion src/FlightRecorder.Entities/Interfaces/ILocationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public interface ILocationManager
{
Task<Location> AddAsync(string name);
Task<Location> GetAsync(Expression<Func<Location, bool>> predicate);
IAsyncEnumerable<Location> ListAsync(Expression<Func<Location, bool>> predicate, int pageNumber, int pageSize);
IAsyncEnumerable<Location> ListAsync(Expression<Func<Location, bool>> predicate, int pageNumber, int pageSize);
Task<int> CountAsync();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public interface IManufacturerManager
{
Task<Manufacturer> AddAsync(string name);
Task<Manufacturer> GetAsync(Expression<Func<Manufacturer, bool>> predicate);
IAsyncEnumerable<Manufacturer> ListAsync(Expression<Func<Manufacturer, bool>> predicate, int pageNumber, int pageSize);
IAsyncEnumerable<Manufacturer> ListAsync(Expression<Func<Manufacturer, bool>> predicate, int pageNumber, int pageSize);
Task<int> CountAsync();
}
}
1 change: 1 addition & 0 deletions src/FlightRecorder.Entities/Interfaces/IModelManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public interface IModelManager
Task<Model> AddAsync(string name, string manufacturerName);
Task<Model> GetAsync(Expression<Func<Model, bool>> predicate);
IAsyncEnumerable<Model> ListAsync(Expression<Func<Model, bool>> predicate, int pageNumber, int pageSize);
Task<int> CountAsync();
IAsyncEnumerable<Model> ListByManufacturerAsync(string manufacturerName, int pageNumber, int pageSize);
}
}
1 change: 1 addition & 0 deletions src/FlightRecorder.Entities/Interfaces/ISightingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public interface ISightingManager
Task<Sighting> AddAsync(FlattenedSighting flattened);
Task<Sighting> GetAsync(Expression<Func<Sighting, bool>> predicate);
IAsyncEnumerable<Sighting> ListAsync(Expression<Func<Sighting, bool>> predicate, int pageNumber, int pageSize);
Task<int> CountAsync();
Task<IAsyncEnumerable<Sighting>> ListByAircraftAsync(string registration, int pageNumber, int pageSize);
Task<IAsyncEnumerable<Sighting>> ListByRouteAsync(string embarkation, string destination, int pageNumber, int pageSize);
Task<IAsyncEnumerable<Sighting>> ListByAirlineAsync(string airlineName, int pageNumber, int pageSize);
Expand Down
6 changes: 3 additions & 3 deletions src/FlightRecorder.Mvc/FlightRecorder.Mvc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ReleaseVersion>1.10.0.0</ReleaseVersion>
<FileVersion>1.10.0.0</FileVersion>
<ProductVersion>1.10.0</ProductVersion>
<ReleaseVersion>1.11.0.0</ReleaseVersion>
<FileVersion>1.11.0.0</FileVersion>
<ProductVersion>1.11.0</ProductVersion>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/FlightRecorder.Mvc/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@

<footer class="border-top footer text-muted">
<div class="container">
&copy; 2020, 2021, 2022, 2023, 2024 - Flight Recorder
&copy; 2020, 2021, 2022, 2023, 2024 - David Walker
</div>
</footer>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
Expand Down

0 comments on commit b664ba3

Please sign in to comment.