Code-complete v2 vehicle API
This commit is contained in:
152
PartSource.Api/Controllers/LegacyVehiclesController.cs
Normal file
152
PartSource.Api/Controllers/LegacyVehiclesController.cs
Normal file
@@ -0,0 +1,152 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using PartSource.Data.Models;
|
||||
using PartSource.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using NexpartMake = PartSource.Data.Nexpart.Make;
|
||||
using NexpartModel = PartSource.Data.Nexpart.Model;
|
||||
using NexpartEngine = PartSource.Data.Nexpart.Engine;
|
||||
using NexpartSubmodel = PartSource.Data.Nexpart.SubModel;
|
||||
|
||||
namespace PartSource.Api.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// This controller exists to enable legacy support for the old Nexpart-based vehicle lookup.
|
||||
/// </summary>
|
||||
[Obsolete]
|
||||
[Route("vehicles")]
|
||||
[ApiController]
|
||||
public class LegacyVehiclesController : BaseNexpartController
|
||||
{
|
||||
private readonly VehicleService _vehicleService;
|
||||
|
||||
public LegacyVehiclesController(VehicleService vehicleService)
|
||||
{
|
||||
_vehicleService = vehicleService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("makes")]
|
||||
public async Task<ActionResult> GetMakes()
|
||||
{
|
||||
IList<VehicleMake> vehicleMakes = await _vehicleService.GetMakes();
|
||||
IList<NexpartMake> nexpartMakes = new List<NexpartMake>();
|
||||
|
||||
foreach (VehicleMake make in vehicleMakes)
|
||||
{
|
||||
nexpartMakes.Add(new NexpartMake
|
||||
{
|
||||
Id = make.MakeId,
|
||||
Value = make.Name.Trim()
|
||||
});
|
||||
}
|
||||
|
||||
return Ok(new { data = new { make = nexpartMakes } });
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("models/makeid/{makeId}/modelyear/{year}")]
|
||||
public async Task<ActionResult> GetModels(int makeId, int year)
|
||||
{
|
||||
IList<VehicleModel> vehicleModels = await _vehicleService.GetModels(makeId, year);
|
||||
IList<NexpartModel> nexpartModels = new List<NexpartModel>();
|
||||
|
||||
foreach (VehicleModel model in vehicleModels)
|
||||
{
|
||||
nexpartModels.Add(new NexpartModel
|
||||
{
|
||||
Id = model.ModelId,
|
||||
Value = model.Name.Trim()
|
||||
});
|
||||
}
|
||||
|
||||
return Ok(new { data = new[] { new { model = nexpartModels } } });
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("basevehicle/makeid/{makeId}/modelid/{modelId}/modelyear/{year}")]
|
||||
[Route("basevehicles/makeid/{makeId}/modelid/{modelId}/modelyear/{year}")]
|
||||
public async Task<ActionResult> GetBaseVehicle(int makeId, int modelId, int year)
|
||||
{
|
||||
BaseVehicle baseVehicle = await _vehicleService.GetBaseVehicle(makeId, modelId, year);
|
||||
|
||||
return Ok(new { data = baseVehicle });
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("engines/basevehicleid/{baseVehicleId}")]
|
||||
[Route("engines/basevehicleid/{baseVehicleId}/submodelid/{subModelId}")]
|
||||
public async Task<ActionResult> GetEngines(int baseVehicleId, int? submodelId = null)
|
||||
{
|
||||
IList<NexpartEngine> nexpartEngines = new List<NexpartEngine>();
|
||||
IList<Engine> engines = submodelId == null
|
||||
? await _vehicleService.GetEngines(baseVehicleId)
|
||||
: await _vehicleService.GetEngines(baseVehicleId, (int)submodelId);
|
||||
|
||||
foreach(Engine engine in engines)
|
||||
{
|
||||
nexpartEngines.Add(new NexpartEngine
|
||||
{
|
||||
Id = engine.EngineConfigId,
|
||||
Value = engine.Description.Trim()
|
||||
});
|
||||
}
|
||||
|
||||
return Ok(new { data = new { engine = nexpartEngines } });
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("trim/makeid/{makeId}/modelid/{modelId}/modelyear/{year}")]
|
||||
[Route("submodels/makeid/{makeId}/modelid/{modelId}/modelyear/{year}")]
|
||||
public async Task<ActionResult> GetSubmodels(int makeId, int modelId, int year)
|
||||
{
|
||||
IList<Submodel> submodels = await _vehicleService.GetSubmodels(makeId, modelId, year);
|
||||
IList<NexpartSubmodel> nexpartSubmodels = new List<NexpartSubmodel>();
|
||||
|
||||
foreach (Submodel submodel in submodels)
|
||||
{
|
||||
nexpartSubmodels.Add(new NexpartSubmodel
|
||||
{
|
||||
Id = submodel.SubmodelId.ToString(),
|
||||
Description = submodel.Name.Trim()
|
||||
});
|
||||
}
|
||||
|
||||
return Ok(new { data = new { subModel = submodels } });
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("detail/basevehicleid/{baseVehicleId}/submodelid/{submodelId}/engineconfigid/{engineConfigId}")]
|
||||
public async Task<ActionResult> GetVehicleDetail(int baseVehicleId, int submodelId, int engineConfigId)
|
||||
{
|
||||
Vehicle vehicle = await _vehicleService.GetVehicle(baseVehicleId, engineConfigId, submodelId);
|
||||
|
||||
return Ok(new { data = vehicle });
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("types")]
|
||||
public ActionResult GetVehicleTypes()
|
||||
{
|
||||
return new StatusCodeResult((int)HttpStatusCode.Gone);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("makes/vehicletypeid/{vehicleTypeId}")]
|
||||
public ActionResult GetMakes(int vehicleTypeId)
|
||||
{
|
||||
return new StatusCodeResult((int)HttpStatusCode.Gone);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("models/makeid/{makeId}/modelyear/{year}/vehicletypeid/{vehicleTypeId}")]
|
||||
public ActionResult GetModels(int makeId, int year, int vehicleTypeId)
|
||||
{
|
||||
return new StatusCodeResult((int)HttpStatusCode.Gone);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user