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
{
///
/// This endpoint gets vehicle data from WHI's SEO data.
///
[Route("v2/[controller]")]
[ApiController]
[ApiExplorerSettings(GroupName = "v2")]
public class VehiclesController : BaseApiController
{
private readonly VehicleService _vehicleService;
public VehiclesController(VehicleService vehicleService)
{
_vehicleService = vehicleService;
}
///
/// Get Vehicles
///
/// OK: An array of vehicles matching the query.
/// No Content: The query executed successfully, but no vehicles were found.
[HttpGet("")]
[ProducesResponseType(typeof(IList), 200)]
[ProducesResponseType(204)]
public async Task GetVehicles([FromQuery] VehicleDto vehicleQuery)
{
IList vehicles = await _vehicleService.GetVehicles(vehicleQuery);
return ApiResponse(vehicles);
}
///
/// Get Vehicle by ID
///
/// A WHI VehicleToEngineConfigId
/// OK: The vehicle with the provided VehicleToEngineConfigId.
/// Not Found: No vehicle was found matching the provided VehicleToEngineConfigId.
[HttpGet("{id}")]
[ProducesResponseType(typeof(VehicleDto), 200)]
[ProducesResponseType(404)]
public async Task GetVehicleById(int id)
{
Vehicle vehicle = await _vehicleService.GetVehicleById(id);
return ApiResponse(vehicle);
}
///
/// Get Makes
///
/// OK: An array of makes matching the query.
/// No Content: The query executed successfully, but no makes were found.
[HttpGet("makes")]
[ProducesResponseType(typeof(IList), 200)]
[ProducesResponseType(204)]
public async Task GetMakes([FromQuery] VehicleDto vehicleQuery)
{
IList makes = await _vehicleService.GetMakes(vehicleQuery);
return ApiResponse(makes);
}
///
/// Get Make by ID
///
/// A WHI MakeId
/// OK: The make with the provided MakeId.
/// Not Found: No make was found matching the provided MakeId.
[HttpGet("makes/{id}")]
[ProducesResponseType(typeof(MakeDto), 200)]
[ProducesResponseType(404)]
public async Task GetMakeById(int id)
{
MakeDto make = await _vehicleService.GetMakeById(id);
return ApiResponse(make);
}
///
/// Get Models
///
/// OK: An array of models matching the query.
/// No Content: The query executed successfully, but no models were found.
[HttpGet("models")]
[ProducesResponseType(typeof(IList), 200)]
[ProducesResponseType(204)]
public async Task GetModels([FromQuery] VehicleDto vehicleQuery)
{
IList models = await _vehicleService.GetModels(vehicleQuery);
return ApiResponse(models);
}
///
/// Get Model by ID
///
/// A WHI ModelId
/// OK: The model with the provided ModelId.
/// Not Found: No model was found matching the provided ModelId.
[HttpGet("models/{id}")]
[ProducesResponseType(typeof(ModelDto), 200)]
[ProducesResponseType(404)]
public async Task GetModelById(int id)
{
ModelDto model = await _vehicleService.GetModelById(id);
return ApiResponse(model);
}
///
/// Get Submodels
///
/// /// Note: Submodels can be shared between models. Do not assume a submodel is unique to a given model.
/// OK: An array of submodels matching the query.
/// No Content: The query executed successfully, but no submodels were found.
[HttpGet("submodels")]
[ProducesResponseType(typeof(IList), 200)]
[ProducesResponseType(204)]
public async Task GetSubmodels([FromQuery] VehicleDto vehicleQuery)
{
IList submodels = await _vehicleService.GetSubmodels(vehicleQuery);
return ApiResponse(submodels);
}
///
/// Get Submodel by ID
///
/// Note: Submodels can be shared between models. Do not assume a submodel is unique to a given model.
/// A WHI SubmodelId
/// OK: The submodel with the provided SubmodelId.
/// Not Found: No submodel was found matching the provided SubmodelId.
[HttpGet("submodels/{id}")]
[ProducesResponseType(typeof(SubmodelDto), 200)]
[ProducesResponseType(404)]
public async Task GetSubmodels(int id)
{
SubmodelDto submodel = await _vehicleService.GetSubmodelById(id);
return ApiResponse(submodel);
}
///
/// Get Base Vehicles
///
/// OK: An array of base vehicles matching the query.
/// No Content: The query executed successfully, but no base vehicles were found.
[HttpGet("basevehicles")]
[ProducesResponseType(typeof(IList), 200)]
[ProducesResponseType(204)]
public async Task GetBaseVehicles([FromQuery] VehicleDto vehicleQuery)
{
IList baseVehicles = await _vehicleService.GetBaseVehicles(vehicleQuery);
return ApiResponse(baseVehicles);
}
///
/// Get Base Vehicle by ID
///
/// A WHI BaseVehicleId
/// OK: The base vehicle with the provided BaseVehicleId.
/// Not Found: No base vehicle was found matching the provided BaseVehicleId.
[HttpGet("basevehicles/{id}")]
[ProducesResponseType(typeof(BaseVehicleDto), 200)]
[ProducesResponseType(404)]
public async Task GetBaseVehicleById(int id)
{
BaseVehicleDto baseVehicle = await _vehicleService.GetBaseVehicleById(id);
return ApiResponse(baseVehicle);
}
///
/// Get Engines
///
/// OK: An array of engines matching the query.
/// No Content: The query executed successfully, but no engines were found.
[HttpGet("engines")]
[ProducesResponseType(typeof(IList), 200)]
[ProducesResponseType(204)]
public async Task GetEngines([FromQuery] VehicleDto vehicleQuery)
{
IList engines = await _vehicleService.GetEngines(vehicleQuery);
return ApiResponse(engines);
}
///
/// Get Engine by ID
///
/// A WHI EngineConfigId
/// OK: The engine with the provided EngineConfigId.
/// Not Found: No engine was found matching the provided EngineConfigId.
[HttpGet("engines/{id}")]
[ProducesResponseType(typeof(EngineDto), 200)]
[ProducesResponseType(404)]
public async Task GetEngineById(int id)
{
EngineDto engine = await _vehicleService.GetEngineById(id);
return ApiResponse(engine);
}
}
}