From 6a81fe4f87259564f80e67540efe39d30efac31a Mon Sep 17 00:00:00 2001 From: Tom Raterman Date: Wed, 13 Sep 2023 09:41:33 -0400 Subject: [PATCH] WIP --- PartSource.Api/Controllers/PartsController.cs | 33 +++++++++++++----- PartSource.Api/PartSource.Api.csproj | 1 + PartSource.Api/Startup.cs | 5 +-- .../PartSource.Automation.csproj | 2 +- .../Services/VehicleFitmentService.cs | 33 ------------------ PartSource.Data/Dtos/VehicleFitmentDto.cs | 12 +++---- PartSource.Services/FitmentService.cs | 34 +------------------ .../PartSource.Services.csproj | 2 +- PartSource.sln | 20 ----------- 9 files changed, 37 insertions(+), 105 deletions(-) diff --git a/PartSource.Api/Controllers/PartsController.cs b/PartSource.Api/Controllers/PartsController.cs index a007504..6d719cc 100644 --- a/PartSource.Api/Controllers/PartsController.cs +++ b/PartSource.Api/Controllers/PartsController.cs @@ -19,12 +19,29 @@ namespace PartSource.Api.Controllers private readonly NexpartService _nexpartService; private readonly PartService _partService; private readonly VehicleService _vehicleService; + private readonly FitmentService _fitmentService; - public PartsController(NexpartService nexpartService, PartService partService, VehicleService vehicleService) + public PartsController(NexpartService nexpartService, PartService partService, VehicleService vehicleService, FitmentService fitmentService) { _nexpartService = nexpartService; _partService = partService; _vehicleService = vehicleService; + _fitmentService = fitmentService; + } + + [HttpGet] + [Route("fitment")] + [Route("fitmentnote")] + public async Task GetFitment([FromQuery] string sku, [FromQuery] int vehicleId) + { + VehicleFitmentDto vehicleFitment = await _fitmentService.GetFitmentNotes(sku, vehicleId); + + if (vehicleFitment == null) + { + return NotFound(); + } + + return Ok(vehicleFitment); } [HttpGet] @@ -54,10 +71,10 @@ namespace PartSource.Api.Controllers IList mappings = await _partService.GetDcfMapping(part.LineCode); Item[] items = mappings.Select(m => new Item - { - PartNumber = part.PartNumber, - MfrCode = m.WhiCode - }) + { + PartNumber = part.PartNumber, + MfrCode = m.WhiCode + }) .ToArray(); SmartPageDataSearch smartPageDataSearch = new SmartPageDataSearch @@ -76,9 +93,9 @@ namespace PartSource.Api.Controllers } PartType[] partTypes = smartPageResponse.ResponseBody.Item.Select(i => new PartType - { - Id = i.Part.PartType.Id - }) + { + Id = i.Part.PartType.Id + }) .ToArray(); ApplicationSearch applicationSearch = new ApplicationSearch diff --git a/PartSource.Api/PartSource.Api.csproj b/PartSource.Api/PartSource.Api.csproj index b04d8fa..572789a 100644 --- a/PartSource.Api/PartSource.Api.csproj +++ b/PartSource.Api/PartSource.Api.csproj @@ -35,6 +35,7 @@ + diff --git a/PartSource.Api/Startup.cs b/PartSource.Api/Startup.cs index ec84a24..6d068f2 100644 --- a/PartSource.Api/Startup.cs +++ b/PartSource.Api/Startup.cs @@ -50,8 +50,9 @@ namespace PartSource.Api }); services.AddAutoMapper(typeof(PartSourceProfile)); - - services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/PartSource.Automation/PartSource.Automation.csproj b/PartSource.Automation/PartSource.Automation.csproj index 8609737..68b6933 100644 --- a/PartSource.Automation/PartSource.Automation.csproj +++ b/PartSource.Automation/PartSource.Automation.csproj @@ -21,11 +21,11 @@ + - diff --git a/PartSource.Automation/Services/VehicleFitmentService.cs b/PartSource.Automation/Services/VehicleFitmentService.cs index d8d5a3d..b082315 100644 --- a/PartSource.Automation/Services/VehicleFitmentService.cs +++ b/PartSource.Automation/Services/VehicleFitmentService.cs @@ -122,38 +122,5 @@ namespace PartSource.Automation.Services return vehicles.ToList(); } - - public IList GetVehicleFitmentForPart(string partNumber, string lineCode, int maxVehicles = 0) - { - if (string.IsNullOrEmpty(partNumber) || string.IsNullOrEmpty(lineCode)) - { - return null; - } - - partNumber = Regex.Replace(partNumber, "[^a-zA-Z0-9\\-]", string.Empty); - - IQueryable whiCodes = _fitmentContext.DcfMappings - .Where(d => d.LineCode == lineCode) - .Select(d => d.WhiCode); - - IQueryable vehicles = _fitmentContext.Fitments - .Where(f => f.PartNumber == partNumber && whiCodes.Contains(f.LineCode)) - .Join(_fitmentContext.Vehicles, - f => new { f.BaseVehicleId, f.EngineConfigId }, - v => new { v.BaseVehicleId, v.EngineConfigId }, - (f, v) => new VehicleFitmentDto - { - Fitment = f, - Vehicle = v - }) - .Distinct(); - - if (maxVehicles > 0) - { - vehicles = vehicles.Take(maxVehicles); - } - - return vehicles.ToList(); - } } } diff --git a/PartSource.Data/Dtos/VehicleFitmentDto.cs b/PartSource.Data/Dtos/VehicleFitmentDto.cs index 56bf211..d1b29ed 100644 --- a/PartSource.Data/Dtos/VehicleFitmentDto.cs +++ b/PartSource.Data/Dtos/VehicleFitmentDto.cs @@ -5,10 +5,8 @@ using System.Text; namespace PartSource.Data.Dtos { - public class VehicleFitmentDto - { - public Fitment Fitment { get; set; } - - public Vehicle Vehicle { get; set; } - } -} + public class VehicleFitmentDto : VehicleFitment + { + public IList SubmodelNames { get; set; } + } +} \ No newline at end of file diff --git a/PartSource.Services/FitmentService.cs b/PartSource.Services/FitmentService.cs index 945cc30..a32a80a 100644 --- a/PartSource.Services/FitmentService.cs +++ b/PartSource.Services/FitmentService.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; using PartSource.Data.Contexts; using PartSource.Data.Dtos; using PartSource.Data.Models; @@ -155,38 +156,5 @@ namespace PartSource.Services return vehicles.ToList(); } - - public IList GetVehicleFitmentForPart(string partNumber, string lineCode, int maxVehicles = 0) - { - if (string.IsNullOrEmpty(partNumber) || string.IsNullOrEmpty(lineCode)) - { - return null; - } - - partNumber = Regex.Replace(partNumber, "[^a-zA-Z0-9\\-]", string.Empty); - - IQueryable whiCodes = _fitmentContext.DcfMappings - .Where(d => d.LineCode == lineCode) - .Select(d => d.WhiCode); - - IQueryable vehicles = _fitmentContext.Fitments - .Where(f => f.PartNumber == partNumber && whiCodes.Contains(f.LineCode)) - .Join(_fitmentContext.Vehicles, - f => new { f.BaseVehicleId, f.EngineConfigId }, - v => new { v.BaseVehicleId, v.EngineConfigId }, - (f, v) => new VehicleFitmentDto - { - Fitment = f, - Vehicle = v - }) - .Distinct(); - - if (maxVehicles > 0) - { - vehicles = vehicles.Take(maxVehicles); - } - - return vehicles.ToList(); - } } } diff --git a/PartSource.Services/PartSource.Services.csproj b/PartSource.Services/PartSource.Services.csproj index 38a3ec3..6d967c3 100644 --- a/PartSource.Services/PartSource.Services.csproj +++ b/PartSource.Services/PartSource.Services.csproj @@ -14,10 +14,10 @@ + - diff --git a/PartSource.sln b/PartSource.sln index f439b13..198692f 100644 --- a/PartSource.sln +++ b/PartSource.sln @@ -11,8 +11,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PartSource.Services", "Part EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PartSource.Automation", "PartSource.Automation\PartSource.Automation.csproj", "{C85D675B-A76C-4F9C-9C57-1E063211C946}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shopify", "..\ratermania\Packages\Shopify\Shopify.csproj", "{1A9096CE-AF40-4DBA-A754-93F8CFC1EBDA}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Also Debug|Any CPU = Also Debug|Any CPU @@ -98,24 +96,6 @@ Global {C85D675B-A76C-4F9C-9C57-1E063211C946}.Release|x64.Build.0 = Release|Any CPU {C85D675B-A76C-4F9C-9C57-1E063211C946}.Release|x86.ActiveCfg = Release|Any CPU {C85D675B-A76C-4F9C-9C57-1E063211C946}.Release|x86.Build.0 = Release|Any CPU - {1A9096CE-AF40-4DBA-A754-93F8CFC1EBDA}.Also Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1A9096CE-AF40-4DBA-A754-93F8CFC1EBDA}.Also Debug|Any CPU.Build.0 = Debug|Any CPU - {1A9096CE-AF40-4DBA-A754-93F8CFC1EBDA}.Also Debug|x64.ActiveCfg = Debug|Any CPU - {1A9096CE-AF40-4DBA-A754-93F8CFC1EBDA}.Also Debug|x64.Build.0 = Debug|Any CPU - {1A9096CE-AF40-4DBA-A754-93F8CFC1EBDA}.Also Debug|x86.ActiveCfg = Debug|Any CPU - {1A9096CE-AF40-4DBA-A754-93F8CFC1EBDA}.Also Debug|x86.Build.0 = Debug|Any CPU - {1A9096CE-AF40-4DBA-A754-93F8CFC1EBDA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1A9096CE-AF40-4DBA-A754-93F8CFC1EBDA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1A9096CE-AF40-4DBA-A754-93F8CFC1EBDA}.Debug|x64.ActiveCfg = Debug|Any CPU - {1A9096CE-AF40-4DBA-A754-93F8CFC1EBDA}.Debug|x64.Build.0 = Debug|Any CPU - {1A9096CE-AF40-4DBA-A754-93F8CFC1EBDA}.Debug|x86.ActiveCfg = Debug|Any CPU - {1A9096CE-AF40-4DBA-A754-93F8CFC1EBDA}.Debug|x86.Build.0 = Debug|Any CPU - {1A9096CE-AF40-4DBA-A754-93F8CFC1EBDA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1A9096CE-AF40-4DBA-A754-93F8CFC1EBDA}.Release|Any CPU.Build.0 = Release|Any CPU - {1A9096CE-AF40-4DBA-A754-93F8CFC1EBDA}.Release|x64.ActiveCfg = Release|Any CPU - {1A9096CE-AF40-4DBA-A754-93F8CFC1EBDA}.Release|x64.Build.0 = Release|Any CPU - {1A9096CE-AF40-4DBA-A754-93F8CFC1EBDA}.Release|x86.ActiveCfg = Release|Any CPU - {1A9096CE-AF40-4DBA-A754-93F8CFC1EBDA}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE