State of OMG-LEGION prior to merge
This commit is contained in:
@@ -5,91 +5,128 @@ using PartSource.Data.Models;
|
||||
using PartSource.Data.Nexpart;
|
||||
using PartSource.Services;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Part = PartSource.Data.Models.Part;
|
||||
|
||||
namespace PartSource.Api.Controllers
|
||||
{
|
||||
[Route("[controller]")]
|
||||
[Route("v2/[controller]")]
|
||||
[ApiController]
|
||||
[ApiExplorerSettings(GroupName = "v1")]
|
||||
public class PartsController : BaseNexpartController
|
||||
{
|
||||
private readonly NexpartService _nexpartService;
|
||||
private readonly PartService _partService;
|
||||
private readonly VehicleService _vehicleService;
|
||||
|
||||
public PartsController(NexpartService nexpartService, PartService partService)
|
||||
public PartsController(NexpartService nexpartService, PartService partService, VehicleService vehicleService)
|
||||
{
|
||||
this._nexpartService = nexpartService;
|
||||
_nexpartService = nexpartService;
|
||||
_partService = partService;
|
||||
_vehicleService = vehicleService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("PartNumber/{partNumber}/LineCode/{lineCode}")]
|
||||
public ActionResult GetPart(string partNumber, string lineCode)
|
||||
[Route("positions")]
|
||||
public async Task<ActionResult> GetPositions([FromQuery] string sku, [FromQuery] int vehicleId)
|
||||
{
|
||||
new SmartPageDataSearch().Items = new Item[1]
|
||||
{
|
||||
new Item()
|
||||
{
|
||||
PartNumber = partNumber.ToUpperInvariant(),
|
||||
MfrCode = lineCode.ToUpperInvariant()
|
||||
}
|
||||
};
|
||||
return (ActionResult)this.Ok();
|
||||
}
|
||||
Part part = await _partService.GetPartBySku(sku);
|
||||
Vehicle vehicle = await _vehicleService.GetVehicleById(vehicleId);
|
||||
|
||||
[HttpGet]
|
||||
[Route("search/basevehicleid/{baseVehicleId}")]
|
||||
public async Task<ActionResult> Search(int baseVehicleId, [FromQuery] string query)
|
||||
{
|
||||
PartsController partsController = this;
|
||||
PartTypeSearch requestContent = new PartTypeSearch()
|
||||
if (part == null)
|
||||
{
|
||||
SearchString = query,
|
||||
SearchType = "ALL",
|
||||
SearchOptions = "PARTIAL_MATCH",
|
||||
VehicleIdentifier = new VehicleIdentifier()
|
||||
return BadRequest(new
|
||||
{
|
||||
BaseVehicleId = baseVehicleId
|
||||
}
|
||||
};
|
||||
|
||||
PartTypeSearchResponse response = await _nexpartService.SendRequest<PartTypeSearch, PartTypeSearchResponse>(requestContent);
|
||||
|
||||
return partsController.NexpartResponse<PartTypeSearchResponse, PartTypes>(response);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("validate/partTypeId/{partTypeId}/baseVehicleId/{baseVehicleId}")]
|
||||
public async Task<ActionResult> ValidatePartFitment(int partTypeId, int baseVehicleId)
|
||||
{
|
||||
PartsController partsController = this;
|
||||
PartTypesValidateLookup typesValidateLookup = new PartTypesValidateLookup();
|
||||
typesValidateLookup.PartTypes = new PartType[1]
|
||||
{
|
||||
new PartType() { Id = partTypeId }
|
||||
};
|
||||
typesValidateLookup.VehicleIdentifier = new VehicleIdentifier()
|
||||
{
|
||||
BaseVehicleId = baseVehicleId
|
||||
};
|
||||
PartTypesValidateLookup requestContent = typesValidateLookup;
|
||||
PartTypesValidateLookupResponse response = await partsController._nexpartService.SendRequest<PartTypesValidateLookup, PartTypesValidateLookupResponse>(requestContent);
|
||||
return partsController.NexpartResponse<PartTypesValidateLookupResponse, PartTypes>(response);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("search/fitment")]
|
||||
public async Task<ActionResult> FitmentSearch([FromQuery] FitmentSearchDto fitmentSearchDto)
|
||||
{
|
||||
IList<Fitment> fitments = _partService.GetFitments(fitmentSearchDto);
|
||||
|
||||
if (fitments == null)
|
||||
{
|
||||
return NotFound();
|
||||
Message = $"No part data is available for SKU {sku}. Confirm it is available in the database maintained by Sound Press.",
|
||||
Reason = $"{nameof(_partService.GetPartBySku)} returned null"
|
||||
});
|
||||
}
|
||||
|
||||
return Ok(new { Data = fitments });
|
||||
if (vehicle == null)
|
||||
{
|
||||
return BadRequest(new
|
||||
{
|
||||
Message = $"No vehicle data is available for SKU {sku}. Confirm it is available in the database maintained by Sound Press.",
|
||||
Reason = $"{nameof(_vehicleService.GetVehicleById)} returned null"
|
||||
});
|
||||
}
|
||||
|
||||
IList<DcfMapping> mappings = await _partService.GetDcfMapping(part.LineCode);
|
||||
Item[] items = mappings.Select(m => new Item
|
||||
{
|
||||
PartNumber = part.PartNumber,
|
||||
MfrCode = m.WhiCode
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
SmartPageDataSearch smartPageDataSearch = new SmartPageDataSearch
|
||||
{
|
||||
Items = items
|
||||
};
|
||||
|
||||
SmartPageDataSearchResponse smartPageResponse = await _nexpartService.SendRequest<SmartPageDataSearch, SmartPageDataSearchResponse>(smartPageDataSearch);
|
||||
if (smartPageResponse.ResponseBody?.Item == null)
|
||||
{
|
||||
return NotFound(new
|
||||
{
|
||||
Message = $"No WHI data is available for SKU {sku}",
|
||||
Reason = $"{nameof(SmartPageDataSearch)} returned null"
|
||||
});
|
||||
}
|
||||
|
||||
PartType[] partTypes = smartPageResponse.ResponseBody.Item.Select(i => new PartType
|
||||
{
|
||||
Id = i.Part.PartType.Id
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
ApplicationSearch applicationSearch = new ApplicationSearch
|
||||
{
|
||||
VehicleIdentifier = new VehicleIdentifier
|
||||
{
|
||||
BaseVehicleId = vehicle.BaseVehicleId
|
||||
},
|
||||
MfrCode = mappings.Select(m => m.WhiCode).ToArray(),
|
||||
PartType = new[] { new PartType { Id = smartPageResponse.ResponseBody.Item[0].Part.PartType.Id } },
|
||||
Criterion = new[]
|
||||
{
|
||||
new Criterion
|
||||
{
|
||||
Attribute = "REGION",
|
||||
Id = 2
|
||||
}
|
||||
},
|
||||
GroupBy = "PARTTYPE"
|
||||
};
|
||||
|
||||
ApplicationSearchResponse response = await _nexpartService.SendRequest<ApplicationSearch, ApplicationSearchResponse>(applicationSearch);
|
||||
|
||||
if (response.ResponseBody == null)
|
||||
{
|
||||
return NotFound(new
|
||||
{
|
||||
Message = $"No WHI data is available for SKU {sku}",
|
||||
Reason = $"{nameof(ApplicationSearch)} returned null"
|
||||
});
|
||||
}
|
||||
|
||||
IList<string> positions = new List<string>();
|
||||
foreach (App app in response.ResponseBody?.App)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(app.Position) && app.Part == part.PartNumber)
|
||||
{
|
||||
positions.Add(app.Position);
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
VehicleId = vehicleId,
|
||||
Sku = sku,
|
||||
Positions = positions.Distinct()
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
63
PartSource.Api/Controllers/WipersController.cs
Normal file
63
PartSource.Api/Controllers/WipersController.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using PartSource.Data.Dtos;
|
||||
using PartSource.Data.Models;
|
||||
using PartSource.Data.Nexpart;
|
||||
using PartSource.Services;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PartSource.Api.Controllers
|
||||
{
|
||||
[Route("[controller]")]
|
||||
[ApiController]
|
||||
[ApiExplorerSettings(GroupName = "v1")]
|
||||
public class WipersController : BaseNexpartController
|
||||
{
|
||||
private readonly NexpartService _nexpartService;
|
||||
|
||||
public WipersController(NexpartService nexpartService)
|
||||
{
|
||||
_nexpartService = nexpartService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("{baseVehicleId}")]
|
||||
public async Task<ActionResult> GetWipersForVehicle(int baseVehicleId)
|
||||
{
|
||||
ApplicationSearch applicationSearch = new ApplicationSearch
|
||||
{
|
||||
VehicleIdentifier = new VehicleIdentifier
|
||||
{
|
||||
BaseVehicleId = baseVehicleId
|
||||
},
|
||||
MfrCode = new[] { "BOS", "TRI" },
|
||||
PartType = new[]
|
||||
{
|
||||
new PartType { Id = 8852 }
|
||||
},
|
||||
Criterion = new[]
|
||||
{
|
||||
new Criterion
|
||||
{
|
||||
Attribute = "REGION",
|
||||
Id = 2
|
||||
}
|
||||
},
|
||||
GroupBy = "PARTTYPE"
|
||||
};
|
||||
|
||||
ApplicationSearchResponse response = await _nexpartService.SendRequest<ApplicationSearch, ApplicationSearchResponse>(applicationSearch);
|
||||
|
||||
if (response.ResponseBody != null)
|
||||
{
|
||||
return NexpartResponse<ApplicationSearchResponse, Apps>(response);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user