Files
Partsource/PartSource.Api/Controllers/VehiclesController.cs
2020-09-02 20:53:34 -04:00

218 lines
8.0 KiB
C#

using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using PartSource.Data.Dtos;
using PartSource.Data.Models;
using PartSource.Services;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
namespace PartSource.Api.Controllers
{
/// <remarks>
/// This endpoint gets vehicle data from WHI's SEO data.
/// </remarks>
[Route("v2/[controller]")]
[ApiController]
[ApiExplorerSettings(GroupName = "v2")]
public class VehiclesController : BaseApiController
{
private readonly VehicleService _vehicleService;
public VehiclesController(VehicleService vehicleService)
{
_vehicleService = vehicleService;
}
/// <summary>
/// Get Vehicles
/// </summary>
/// <response code="200"><strong>OK:</strong> An array of vehicles matching the query.</response>
/// <response code="204"><strong>No Content:</strong> The query executed successfully, but no vehicles were found.</response>
[HttpGet("")]
[ProducesResponseType(typeof(IList<VehicleDto>), 200)]
[ProducesResponseType(204)]
public async Task<ActionResult> GetVehicles([FromQuery] VehicleDto vehicleQuery)
{
IList<Vehicle> vehicles = await _vehicleService.GetVehicles(vehicleQuery);
return ApiResponse(vehicles);
}
/// <summary>
/// Get Vehicle by ID
/// </summary>
/// <param name="id">A WHI VehicleToEngineConfigId</param>
/// <response code="200"><strong>OK:</strong> The vehicle with the provided VehicleToEngineConfigId.</response>
/// <response code="404"><strong>Not Found:</strong> No vehicle was found matching the provided VehicleToEngineConfigId.</response>
[HttpGet("{id}")]
[ProducesResponseType(typeof(VehicleDto), 200)]
[ProducesResponseType(404)]
public async Task<ActionResult> GetVehicleById(int id)
{
Vehicle vehicle = await _vehicleService.GetVehicleById(id);
return ApiResponse(vehicle);
}
/// <summary>
/// Get Makes
/// </summary>
/// <response code="200"><strong>OK:</strong> An array of makes matching the query.</response>
/// <response code="204"><strong>No Content:</strong> The query executed successfully, but no makes were found.</response>
[HttpGet("makes")]
[ProducesResponseType(typeof(IList<MakeDto>), 200)]
[ProducesResponseType(204)]
public async Task<ActionResult> GetMakes([FromQuery] VehicleDto vehicleQuery)
{
IList<MakeDto> makes = await _vehicleService.GetMakes(vehicleQuery);
return ApiResponse(makes);
}
/// <summary>
/// Get Make by ID
/// </summary>
/// <param name="id">A WHI MakeId</param>
/// <response code="200"><strong>OK:</strong> The make with the provided MakeId.</response>
/// <response code="404"><strong>Not Found:</strong> No make was found matching the provided MakeId.</response>
[HttpGet("makes/{id}")]
[ProducesResponseType(typeof(MakeDto), 200)]
[ProducesResponseType(404)]
public async Task<ActionResult> GetMakeById(int id)
{
MakeDto make = await _vehicleService.GetMakeById(id);
return ApiResponse(make);
}
/// <summary>
/// Get Models
/// </summary>
/// <response code="200"><strong>OK:</strong> An array of models matching the query.</response>
/// <response code="204"><strong>No Content:</strong> The query executed successfully, but no models were found.</response>
[HttpGet("models")]
[ProducesResponseType(typeof(IList<ModelDto>), 200)]
[ProducesResponseType(204)]
public async Task<ActionResult> GetModels([FromQuery] VehicleDto vehicleQuery)
{
IList<ModelDto> models = await _vehicleService.GetModels(vehicleQuery);
return ApiResponse(models);
}
/// <summary>
/// Get Model by ID
/// </summary>
/// <param name="id">A WHI ModelId</param>
/// <response code="200"><strong>OK:</strong> The model with the provided ModelId.</response>
/// <response code="404"><strong>Not Found:</strong> No model was found matching the provided ModelId.</response>
[HttpGet("models/{id}")]
[ProducesResponseType(typeof(ModelDto), 200)]
[ProducesResponseType(404)]
public async Task<ActionResult> GetModelById(int id)
{
ModelDto model = await _vehicleService.GetModelById(id);
return ApiResponse(model);
}
/// <summary>
/// Get Submodels
/// </summary>
/// /// <remarks><em>Note: Submodels can be shared between models. Do not assume a submodel is unique to a given model.</em></remarks>
/// <response code="200"><strong>OK:</strong> An array of submodels matching the query.</response>
/// <response code="204"><strong>No Content:</strong> The query executed successfully, but no submodels were found.</response>
[HttpGet("submodels")]
[ProducesResponseType(typeof(IList<SubmodelDto>), 200)]
[ProducesResponseType(204)]
public async Task<ActionResult> GetSubmodels([FromQuery] VehicleDto vehicleQuery)
{
IList<SubmodelDto> submodels = await _vehicleService.GetSubmodels(vehicleQuery);
return ApiResponse(submodels);
}
/// <summary>
/// Get Submodel by ID
/// </summary>
/// <remarks><em>Note: Submodels can be shared between models. Do not assume a submodel is unique to a given model.</em></remarks>
/// <param name="id">A WHI SubmodelId</param>
/// <response code="200"><strong>OK:</strong> The submodel with the provided SubmodelId.</response>
/// <response code="404"><strong>Not Found:</strong> No submodel was found matching the provided SubmodelId.</response>
[HttpGet("submodels/{id}")]
[ProducesResponseType(typeof(SubmodelDto), 200)]
[ProducesResponseType(404)]
public async Task<ActionResult> GetSubmodels(int id)
{
SubmodelDto submodel = await _vehicleService.GetSubmodelById(id);
return ApiResponse(submodel);
}
/// <summary>
/// Get Base Vehicles
/// </summary>
/// <response code="200"><strong>OK:</strong> An array of base vehicles matching the query.</response>
/// <response code="204"><strong>No Content:</strong> The query executed successfully, but no base vehicles were found.</response>
[HttpGet("basevehicles")]
[ProducesResponseType(typeof(IList<BaseVehicleDto>), 200)]
[ProducesResponseType(204)]
public async Task<ActionResult> GetBaseVehicles([FromQuery] VehicleDto vehicleQuery)
{
IList<BaseVehicleDto> baseVehicles = await _vehicleService.GetBaseVehicles(vehicleQuery);
return ApiResponse(baseVehicles);
}
/// <summary>
/// Get Base Vehicle by ID
/// </summary>
/// <param name="id">A WHI BaseVehicleId</param>
/// <response code="200"><strong>OK:</strong> The base vehicle with the provided BaseVehicleId.</response>
/// <response code="404"><strong>Not Found:</strong> No base vehicle was found matching the provided BaseVehicleId.</response>
[HttpGet("basevehicles/{id}")]
[ProducesResponseType(typeof(BaseVehicleDto), 200)]
[ProducesResponseType(404)]
public async Task<ActionResult> GetBaseVehicleById(int id)
{
BaseVehicleDto baseVehicle = await _vehicleService.GetBaseVehicleById(id);
return ApiResponse(baseVehicle);
}
/// <summary>
/// Get Engines
/// </summary>
/// <response code="200"><strong>OK:</strong> An array of engines matching the query.</response>
/// <response code="204"><strong>No Content:</strong> The query executed successfully, but no engines were found.</response>
[HttpGet("engines")]
[ProducesResponseType(typeof(IList<EngineDto>), 200)]
[ProducesResponseType(204)]
public async Task<ActionResult> GetEngines([FromQuery] VehicleDto vehicleQuery)
{
IList<EngineDto> engines = await _vehicleService.GetEngines(vehicleQuery);
return ApiResponse(engines);
}
/// <summary>
/// Get Engine by ID
/// </summary>
/// <param name="id">A WHI EngineConfigId</param>
/// <response code="200"><strong>OK:</strong> The engine with the provided EngineConfigId.</response>
/// <response code="404"><strong>Not Found:</strong> No engine was found matching the provided EngineConfigId.</response>
[HttpGet("engines/{id}")]
[ProducesResponseType(typeof(EngineDto), 200)]
[ProducesResponseType(404)]
public async Task<ActionResult> GetEngineById(int id)
{
EngineDto engine = await _vehicleService.GetEngineById(id);
return ApiResponse(engine);
}
}
}