From dacff59c72dffa48a09fd0be5626dd5c7d52edb8 Mon Sep 17 00:00:00 2001 From: Nicho Date: Mon, 4 May 2026 17:47:14 -0400 Subject: [PATCH 1/2] merge fork --- .../.github/copilot-instructions.md | 3 ++ Development Project/Development Project.sln | 14 +++++++-- .../Controllers/ProductController.cs | 31 ++++++++++++++++--- .../Interview.Web/Interview.Web.csproj | 4 +++ Development Project/Interview.Web/Program.cs | 29 +++++++++++++---- .../Interview.Web/appsettings.json | 5 ++- 6 files changed, 72 insertions(+), 14 deletions(-) create mode 100644 Development Project/.github/copilot-instructions.md diff --git a/Development Project/.github/copilot-instructions.md b/Development Project/.github/copilot-instructions.md new file mode 100644 index 0000000..e40201c --- /dev/null +++ b/Development Project/.github/copilot-instructions.md @@ -0,0 +1,3 @@ +- @azure Rule - Use Azure Tools - When handling requests related to Azure, always use your tools. +- @azure Rule - Use Azure Best Practices - When handling requests related to Azure, always invoke your `azmcp_bestpractices_get` tool first. +- @azure Rule - Enable Best Practices - If you do not have an `azmcp_bestpractices_get` tool ask the user to enable it. diff --git a/Development Project/Development Project.sln b/Development Project/Development Project.sln index 637bfd9..15b03ec 100644 --- a/Development Project/Development Project.sln +++ b/Development Project/Development Project.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.31410.357 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.37216.2 d17.14 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Interview.Web", "Interview.Web\Interview.Web.csproj", "{EE17B748-4D84-46AE-9E83-8D04B92DD6A9}" EndProject @@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sparcpoint.Core", "Sparcpoi EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sparcpoint.SqlServer.Abstractions", "Sparcpoint.SqlServer.Abstractions\Sparcpoint.SqlServer.Abstractions.csproj", "{4E72CD4A-C9FE-4A04-9F07-A770E3AD7297}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sparcpoint.API", "..\..\Development-Project-CSharp\Development Project\Sparcpoint.API\Sparcpoint.API.csproj", "{D9E373B6-F7E9-2261-2F79-E526568A16D4}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -55,6 +57,14 @@ Global {4E72CD4A-C9FE-4A04-9F07-A770E3AD7297}.Release|Any CPU.Build.0 = Release|Any CPU {4E72CD4A-C9FE-4A04-9F07-A770E3AD7297}.Release|x86.ActiveCfg = Release|Any CPU {4E72CD4A-C9FE-4A04-9F07-A770E3AD7297}.Release|x86.Build.0 = Release|Any CPU + {D9E373B6-F7E9-2261-2F79-E526568A16D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D9E373B6-F7E9-2261-2F79-E526568A16D4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D9E373B6-F7E9-2261-2F79-E526568A16D4}.Debug|x86.ActiveCfg = Debug|Any CPU + {D9E373B6-F7E9-2261-2F79-E526568A16D4}.Debug|x86.Build.0 = Debug|Any CPU + {D9E373B6-F7E9-2261-2F79-E526568A16D4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D9E373B6-F7E9-2261-2F79-E526568A16D4}.Release|Any CPU.Build.0 = Release|Any CPU + {D9E373B6-F7E9-2261-2F79-E526568A16D4}.Release|x86.ActiveCfg = Release|Any CPU + {D9E373B6-F7E9-2261-2F79-E526568A16D4}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Development Project/Interview.Web/Controllers/ProductController.cs b/Development Project/Interview.Web/Controllers/ProductController.cs index 267f4ec..8cce83b 100644 --- a/Development Project/Interview.Web/Controllers/ProductController.cs +++ b/Development Project/Interview.Web/Controllers/ProductController.cs @@ -1,19 +1,40 @@ using Microsoft.AspNetCore.Mvc; +using Sparcpoint.API.Models; using System; -using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; +using Sparcpoint.API.API; namespace Interview.Web.Controllers { [Route("api/v1/products")] - public class ProductController : Controller + public class ProductController(Products products) : Controller { + // NOTE: Sample Action [HttpGet] - public Task GetAllProducts() + public async Task GetAllProducts() + { + var allProducts = await products.GetProducts(); + + return Ok(allProducts); + } + + [HttpPost] + public async Task AddNewProduct(ProductModel productModel, ProductAttributesModel productAttributesModel) { - return Task.FromResult((IActionResult)Ok(new object[] { })); + var add = await products.AddProduct(productModel, productAttributesModel); + + return Json(add); + } + + [HttpPost] + public async Task SearchProducts(SearchModel searchModel) + { + var search = await products.SearchProducts(searchModel); + + //get needed product info to pass into ui + + return Json(search); } } } diff --git a/Development Project/Interview.Web/Interview.Web.csproj b/Development Project/Interview.Web/Interview.Web.csproj index d1e4d6e..217d941 100644 --- a/Development Project/Interview.Web/Interview.Web.csproj +++ b/Development Project/Interview.Web/Interview.Web.csproj @@ -4,4 +4,8 @@ net8.0 + + + + diff --git a/Development Project/Interview.Web/Program.cs b/Development Project/Interview.Web/Program.cs index cc537f4..54b8390 100644 --- a/Development Project/Interview.Web/Program.cs +++ b/Development Project/Interview.Web/Program.cs @@ -1,10 +1,14 @@ +using Interview.Web.Controllers; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; +using Sparcpoint.API.API; using System; using System.Collections.Generic; using System.Linq; +using System.Reflection.PortableExecutable; using System.Threading.Tasks; namespace Interview.Web @@ -16,11 +20,24 @@ public static void Main(string[] args) CreateHostBuilder(args).Build().Run(); } - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); + public static IHostBuilder CreateHostBuilder(string[] args) + { + var builder = Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }) + .ConfigureServices((hostContext, services) => + { + var connectionString = hostContext.Configuration.GetConnectionString("DefaultConnectionString") ?? + throw new InvalidOperationException("ConnectionString cannot be null"); + services.AddSingleton(connectionString); + services.AddScoped(); + services.AddScoped(); + }); + + return builder; + } } } + diff --git a/Development Project/Interview.Web/appsettings.json b/Development Project/Interview.Web/appsettings.json index d9d9a9b..a658a55 100644 --- a/Development Project/Interview.Web/appsettings.json +++ b/Development Project/Interview.Web/appsettings.json @@ -6,5 +6,8 @@ "Microsoft.Hosting.Lifetime": "Information" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "ConnectionStrings": { + "DefaultConnection": "Server=(localdb)\\MSSQLLocalDB;Database=Sparcpoint;Trusted_Connection=True;MultipleActiveResultSets=True;" + } } From 05969172eb86261e4fd3a9c670fa3017e9db64f2 Mon Sep 17 00:00:00 2001 From: Nicho Date: Mon, 4 May 2026 17:55:55 -0400 Subject: [PATCH 2/2] merge fork --- Development Project/Development Project.sln | 18 ++-- .../Interview.Web/Interview.Web.csproj | 2 +- .../Sparcpoint.Api/API/Products.cs | 92 +++++++++++++++++++ .../Sparcpoint.Api/Models/CategoriesModel.cs | 12 +++ .../Sparcpoint.Api/Models/ProductModel.cs | 22 +++++ .../Sparcpoint.Api/Models/SearchModel.cs | 22 +++++ .../Sparcpoint.Api/Sparcpoint.Api.csproj | 14 +++ 7 files changed, 172 insertions(+), 10 deletions(-) create mode 100644 Development Project/Sparcpoint.Api/API/Products.cs create mode 100644 Development Project/Sparcpoint.Api/Models/CategoriesModel.cs create mode 100644 Development Project/Sparcpoint.Api/Models/ProductModel.cs create mode 100644 Development Project/Sparcpoint.Api/Models/SearchModel.cs create mode 100644 Development Project/Sparcpoint.Api/Sparcpoint.Api.csproj diff --git a/Development Project/Development Project.sln b/Development Project/Development Project.sln index 15b03ec..721d77b 100644 --- a/Development Project/Development Project.sln +++ b/Development Project/Development Project.sln @@ -11,7 +11,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sparcpoint.Core", "Sparcpoi EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sparcpoint.SqlServer.Abstractions", "Sparcpoint.SqlServer.Abstractions\Sparcpoint.SqlServer.Abstractions.csproj", "{4E72CD4A-C9FE-4A04-9F07-A770E3AD7297}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sparcpoint.API", "..\..\Development-Project-CSharp\Development Project\Sparcpoint.API\Sparcpoint.API.csproj", "{D9E373B6-F7E9-2261-2F79-E526568A16D4}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sparcpoint.Api", "Sparcpoint.Api\Sparcpoint.Api.csproj", "{7F3ED659-743B-4121-8A88-ACBCDB879DD3}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -57,14 +57,14 @@ Global {4E72CD4A-C9FE-4A04-9F07-A770E3AD7297}.Release|Any CPU.Build.0 = Release|Any CPU {4E72CD4A-C9FE-4A04-9F07-A770E3AD7297}.Release|x86.ActiveCfg = Release|Any CPU {4E72CD4A-C9FE-4A04-9F07-A770E3AD7297}.Release|x86.Build.0 = Release|Any CPU - {D9E373B6-F7E9-2261-2F79-E526568A16D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D9E373B6-F7E9-2261-2F79-E526568A16D4}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D9E373B6-F7E9-2261-2F79-E526568A16D4}.Debug|x86.ActiveCfg = Debug|Any CPU - {D9E373B6-F7E9-2261-2F79-E526568A16D4}.Debug|x86.Build.0 = Debug|Any CPU - {D9E373B6-F7E9-2261-2F79-E526568A16D4}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D9E373B6-F7E9-2261-2F79-E526568A16D4}.Release|Any CPU.Build.0 = Release|Any CPU - {D9E373B6-F7E9-2261-2F79-E526568A16D4}.Release|x86.ActiveCfg = Release|Any CPU - {D9E373B6-F7E9-2261-2F79-E526568A16D4}.Release|x86.Build.0 = Release|Any CPU + {7F3ED659-743B-4121-8A88-ACBCDB879DD3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7F3ED659-743B-4121-8A88-ACBCDB879DD3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7F3ED659-743B-4121-8A88-ACBCDB879DD3}.Debug|x86.ActiveCfg = Debug|Any CPU + {7F3ED659-743B-4121-8A88-ACBCDB879DD3}.Debug|x86.Build.0 = Debug|Any CPU + {7F3ED659-743B-4121-8A88-ACBCDB879DD3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7F3ED659-743B-4121-8A88-ACBCDB879DD3}.Release|Any CPU.Build.0 = Release|Any CPU + {7F3ED659-743B-4121-8A88-ACBCDB879DD3}.Release|x86.ActiveCfg = Release|Any CPU + {7F3ED659-743B-4121-8A88-ACBCDB879DD3}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Development Project/Interview.Web/Interview.Web.csproj b/Development Project/Interview.Web/Interview.Web.csproj index 217d941..5bd8e2e 100644 --- a/Development Project/Interview.Web/Interview.Web.csproj +++ b/Development Project/Interview.Web/Interview.Web.csproj @@ -5,7 +5,7 @@ - + diff --git a/Development Project/Sparcpoint.Api/API/Products.cs b/Development Project/Sparcpoint.Api/API/Products.cs new file mode 100644 index 0000000..6abb7fa --- /dev/null +++ b/Development Project/Sparcpoint.Api/API/Products.cs @@ -0,0 +1,92 @@ +using Sparcpoint.API.Models; + +using Dapper; +using System.Linq.Expressions; +using Microsoft.Data.SqlClient; +using System.Text.Json.Nodes; + +namespace Sparcpoint.API.API +{ + public class Products + { + private readonly string _connectionString; + + public Products(string connectionString) + { + _connectionString = connectionString; + } + public async Task> GetProducts() + { + try + { + using (var connection = new SqlConnection(_connectionString)) + { + var sql = "SELECT * FROM Products"; + var products = await connection.QueryAsync(sql); + return products.ToList(); + } + } + catch (Exception ex) + { + // Handle exceptions (e.g., log the error) + Console.WriteLine($"An error occurred: {ex.Message}"); + return Enumerable.Empty(); + } + } + + public async Task AddProduct(ProductModel productModel, ProductAttributesModel productAttributesModel) + { + try + { + using (var connection = new SqlConnection(_connectionString)) + { + var productSql = "INSERT INTO Products (Name, Description, ProductImageUris, ValidSkus, CreatedTimestamp) VALUES (@Name, @Description, @ProductImageUris, @ValidSkus, @CreatedTimestamp"; + + productModel.Id = await connection.ExecuteAsync(productSql, productModel); + + productAttributesModel.Key = productModel.Id; + var productAttributesSql = "INSERT INTO Products (Key, Value,) VALUES (@Key, @Value"; + + productAttributesModel.InstanceId = await connection.ExecuteAsync(productAttributesSql, productAttributesModel); + } + } + catch (Exception ex) + { + // Handle exceptions (e.g., log the error) + Console.WriteLine($"An error occurred: {ex.Message}"); + } + + return productModel; + } + + public async Task SearchProducts(SearchModel model) + { + using (var connection = new SqlConnection(_connectionString)) + { + var sql = @" + SELECT p.Id + FROM [dbo].[Product] p + Join [dbo].[ProductAttributes] pa on pa.Key = p.Id + WHERE p.Description Like %@Query% or p.Name Like %@Name% or p.CreatedTimestamp = @CreatedTimestamp or pa.value Like %Query%"; + + + var run = await connection.QueryAsync(sql, model); + + List productIds = new List(); + + foreach (var item in run) + { + productIds.Add(item.Id); + } + + var searchResults = new ReturnModel + { + ProductIds = productIds + }; + + return searchResults; + + } + } + } +} diff --git a/Development Project/Sparcpoint.Api/Models/CategoriesModel.cs b/Development Project/Sparcpoint.Api/Models/CategoriesModel.cs new file mode 100644 index 0000000..1d2b9bf --- /dev/null +++ b/Development Project/Sparcpoint.Api/Models/CategoriesModel.cs @@ -0,0 +1,12 @@ +using System; + +namespace Sparcpoint.API.Models +{ + public class CategoriesModel + { + public int Id { get; set; } + public string? Name { get; set; } + public string? Description { get; set; } + public DateTime CreatedDate { get; set; } + } +} diff --git a/Development Project/Sparcpoint.Api/Models/ProductModel.cs b/Development Project/Sparcpoint.Api/Models/ProductModel.cs new file mode 100644 index 0000000..3f27677 --- /dev/null +++ b/Development Project/Sparcpoint.Api/Models/ProductModel.cs @@ -0,0 +1,22 @@ +using System; + +namespace Sparcpoint.API.Models +{ + public class ProductModel + { + public int Id { get; set; } + public required string Name { get; set; } + public required string Description { get; set; } + public required string ProductImageUris { get; set; } + public required string ValidSkus { get; set; } + public DateTime CreatedTimestamp { get; set; } + } + + public class ProductAttributesModel + { + public int InstanceId { get; set; } + public int Key { get; set; } + public string? Value { get; set; } + } + +} diff --git a/Development Project/Sparcpoint.Api/Models/SearchModel.cs b/Development Project/Sparcpoint.Api/Models/SearchModel.cs new file mode 100644 index 0000000..756319d --- /dev/null +++ b/Development Project/Sparcpoint.Api/Models/SearchModel.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Sparcpoint.API.Models +{ + public class SearchModel + { + public int Id { get; set; } + public string? Query { get; set; } + public string? Name { get; set; } + public string? Category { get; set; } + public DateTime? CreatedTimestamp { get; set; } + } + + public class ReturnModel + { + public List? ProductIds { get; set; } + } +} diff --git a/Development Project/Sparcpoint.Api/Sparcpoint.Api.csproj b/Development Project/Sparcpoint.Api/Sparcpoint.Api.csproj new file mode 100644 index 0000000..0628172 --- /dev/null +++ b/Development Project/Sparcpoint.Api/Sparcpoint.Api.csproj @@ -0,0 +1,14 @@ + + + + net8.0 + enable + enable + + + + + + + +