Merge from master
This commit is contained in:
@@ -4,6 +4,7 @@ using PartSource.Data.Dtos;
|
||||
using PartSource.Data.Models;
|
||||
using PartSource.Data.Nexpart;
|
||||
using PartSource.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
@@ -41,6 +42,77 @@ namespace PartSource.Api.Controllers
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
string[] segments = vehicleFitment.NoteText.Split(']');
|
||||
vehicleFitment.PartDescription = segments[0].TrimStart('[');
|
||||
vehicleFitment.DriveTypes = GetDriveTypesFromNote(vehicleFitment.NoteText);
|
||||
vehicleFitment.Notes = segments[1].Split(';')
|
||||
.Select(n => n.Trim())
|
||||
.ToList();
|
||||
}
|
||||
|
||||
catch
|
||||
{
|
||||
throw new InvalidOperationException($"The note_text field provided by WHI for {vehicleFitment.LineCode} {vehicleFitment.PartNumber} was in an invalid format.");
|
||||
}
|
||||
|
||||
SmartPageDataSearch smartPageDataSearch = new SmartPageDataSearch
|
||||
{
|
||||
Items = new[]
|
||||
{
|
||||
new Item { PartNumber = vehicleFitment.PartNumber, MfrCode = vehicleFitment.LineCode }
|
||||
}
|
||||
};
|
||||
|
||||
SmartPageDataSearchResponse smartPageResponse = await _nexpartService.SendRequest<SmartPageDataSearch, SmartPageDataSearchResponse>(smartPageDataSearch);
|
||||
if (smartPageResponse.ResponseBody?.Item != null)
|
||||
{
|
||||
PartType[] partTypes = smartPageResponse.ResponseBody.Item.Select(i => new PartType
|
||||
{
|
||||
Id = i.Part.PartType.Id
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
ApplicationSearch applicationSearch = new ApplicationSearch
|
||||
{
|
||||
VehicleIdentifier = new VehicleIdentifier
|
||||
{
|
||||
BaseVehicleId = vehicleFitment.BaseVehicleId,
|
||||
EngineConfigId = vehicleFitment.EngineConfigId
|
||||
},
|
||||
MfrCode = new[] { vehicleFitment.LineCode },
|
||||
PartType = partTypes,
|
||||
GroupBy = "MFR",
|
||||
QuestionOption = "QUESTION_OTHERWISE_APP"
|
||||
};
|
||||
|
||||
ApplicationSearchResponse response = await _nexpartService.SendRequest<ApplicationSearch, ApplicationSearchResponse>(applicationSearch);
|
||||
if (response.ResponseBody != null && response.ResponseBody is Questions)
|
||||
{
|
||||
Question driveTypeQuestion = ((Questions)response.ResponseBody).Question
|
||||
.Where(q => q.Attribute == "DRIVE_TYPE")
|
||||
.FirstOrDefault();
|
||||
|
||||
if (driveTypeQuestion != null)
|
||||
{
|
||||
foreach (Answer answer in driveTypeQuestion.Answer)
|
||||
{
|
||||
applicationSearch.Criterion = new[]
|
||||
{
|
||||
new Criterion { Attribute = "DRIVE_TYPE", Id = answer.Id}
|
||||
};
|
||||
|
||||
ApplicationSearchResponse driveTypeResponse = await _nexpartService.SendRequest<ApplicationSearch, ApplicationSearchResponse>(applicationSearch);
|
||||
if (driveTypeResponse.ResponseBody != null && ((Apps)driveTypeResponse.ResponseBody).App.Where(a => a.Part == vehicleFitment.PartNumber).Any())
|
||||
{
|
||||
vehicleFitment.DriveTypes.Add(answer.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(vehicleFitment);
|
||||
}
|
||||
|
||||
@@ -51,15 +123,24 @@ namespace PartSource.Api.Controllers
|
||||
Part part = await _partService.GetPartBySku(sku);
|
||||
Vehicle vehicle = await _vehicleService.GetVehicleById(vehicleId);
|
||||
|
||||
if (part == null || vehicle == null)
|
||||
if (part == null)
|
||||
{
|
||||
return BadRequest(new
|
||||
{
|
||||
Message = $"No data is available for SKU {sku}. Confirm it is available in the database maintained by Sound Press.",
|
||||
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"
|
||||
});
|
||||
}
|
||||
|
||||
if (vehicle == null)
|
||||
{
|
||||
return BadRequest(new
|
||||
{
|
||||
Message = $"No vehicle data is available for vehicle ID {vehicleId}. 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
|
||||
{
|
||||
@@ -87,7 +168,7 @@ namespace PartSource.Api.Controllers
|
||||
{
|
||||
Id = i.Part.PartType.Id
|
||||
})
|
||||
.ToArray();
|
||||
.ToArray();
|
||||
|
||||
ApplicationSearch applicationSearch = new ApplicationSearch
|
||||
{
|
||||
@@ -98,13 +179,13 @@ namespace PartSource.Api.Controllers
|
||||
MfrCode = mappings.Select(m => m.WhiCode).ToArray(),
|
||||
PartType = new[] { new PartType { Id = smartPageResponse.ResponseBody.Item[0].Part.PartType.Id } },
|
||||
Criterion = new[]
|
||||
{
|
||||
new Criterion
|
||||
{
|
||||
new Criterion
|
||||
{
|
||||
Attribute = "REGION",
|
||||
Id = 2
|
||||
}
|
||||
},
|
||||
Attribute = "REGION",
|
||||
Id = 2
|
||||
}
|
||||
},
|
||||
GroupBy = "PARTTYPE"
|
||||
};
|
||||
|
||||
@@ -120,7 +201,7 @@ namespace PartSource.Api.Controllers
|
||||
}
|
||||
|
||||
IList<string> positions = new List<string>();
|
||||
foreach (App app in response.ResponseBody?.App)
|
||||
foreach (App app in ((Apps)response.ResponseBody)?.App)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(app.Position) && app.Part == part.PartNumber)
|
||||
{
|
||||
@@ -136,5 +217,33 @@ namespace PartSource.Api.Controllers
|
||||
});
|
||||
}
|
||||
|
||||
private IList<string> GetDriveTypesFromNote(string fitmentNote)
|
||||
{
|
||||
fitmentNote = fitmentNote.ToUpperInvariant();
|
||||
IList<string> driveTypes = new List<string>();
|
||||
|
||||
if (fitmentNote.Contains("FWD"))
|
||||
{
|
||||
driveTypes.Add("FWD");
|
||||
}
|
||||
|
||||
if (fitmentNote.Contains("RWD"))
|
||||
{
|
||||
driveTypes.Add("RWD");
|
||||
}
|
||||
|
||||
if (fitmentNote.Contains("AWD"))
|
||||
{
|
||||
driveTypes.Add("AWD");
|
||||
}
|
||||
|
||||
if (fitmentNote.Contains("4WD"))
|
||||
{
|
||||
driveTypes.Add("4WD");
|
||||
}
|
||||
|
||||
return driveTypes;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace PartSource.Api.Controllers
|
||||
|
||||
if (response.ResponseBody != null)
|
||||
{
|
||||
return NexpartResponse<ApplicationSearchResponse, Apps>(response);
|
||||
return NexpartResponse<ApplicationSearchResponse, object>(response);
|
||||
}
|
||||
|
||||
else
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<UserSecretsId>f9e2fd37-0f2d-4e3a-955a-8e49a16fce1c</UserSecretsId>
|
||||
<Configurations>Debug;Release;Also Debug</Configurations>
|
||||
<SatelliteResourceLanguages>en-us;en</SatelliteResourceLanguages>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
@@ -34,6 +35,7 @@
|
||||
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.5" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="Ratermania.Shopify" Version="6.16.11" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.1" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.ReDoc" Version="6.3.1" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,13 +1,4 @@
|
||||
{
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:31337",
|
||||
"sslPort": 0
|
||||
}
|
||||
},
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
@@ -18,12 +9,20 @@
|
||||
},
|
||||
"PartSource.Api": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "api/values",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"applicationUrl": "https://localhost:5001;http://localhost:5000"
|
||||
}
|
||||
},
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:31337",
|
||||
"sslPort": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
"PartSourceDatabase": "Server=tcp:ps-whi.database.windows.net,1433;Initial Catalog=ps-whi-stage;Persist Security Info=False;User ID=ps-whi;Password=9-^*N5dw!6:|.5Q;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;",
|
||||
"FitmentDatabase": "Server=tcp:ps-automation.eastus2.cloudapp.azure.com,1433;Initial Catalog=WhiFitment;User ID=automation;Password=)6L)XP%m(x-UU#M;Encrypt=True;TrustServerCertificate=True;Connection Timeout=300"
|
||||
//"FitmentDatabase": "Data Source=localhost;Initial Catalog=WhiFitment;Integrated Security=true"
|
||||
"FitmentDatabase": "Server=tcp:ps-automation.eastus2.cloudapp.azure.com,1433;Initial Catalog=WhiFitment;User ID=sa;Password=GZ0`-ekd~[2u;Encrypt=True;TrustServerCertificate=True;Connection Timeout=300"
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
|
||||
Reference in New Issue
Block a user