Compare commits
No commits in common. "27dd2af627553ee782a7f3524a91fc1e40292a51" and "a311cf9f3e648c0be92f7f6cf8c5026d2a5de570" have entirely different histories.
27dd2af627
...
a311cf9f3e
@ -5,95 +5,78 @@ using System.Linq;
|
|||||||
|
|
||||||
namespace RhSolutions.Api.Controllers
|
namespace RhSolutions.Api.Controllers
|
||||||
{
|
{
|
||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
public class ProductsController : ControllerBase
|
public class ProductsController : ControllerBase
|
||||||
{
|
{
|
||||||
private RhSolutionsContext dbContext;
|
private RhSolutionsContext dbContext;
|
||||||
private IPricelistParser parser;
|
private IPricelistParser parser;
|
||||||
|
|
||||||
public ProductsController(RhSolutionsContext dbContext, IPricelistParser parser)
|
public ProductsController(RhSolutionsContext dbContext, IPricelistParser parser)
|
||||||
{
|
{
|
||||||
this.dbContext = dbContext;
|
this.dbContext = dbContext;
|
||||||
this.parser = parser;
|
this.parser = parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Возвращает все продукты в базе данных
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet]
|
|
||||||
public IAsyncEnumerable<Product> GetProducts()
|
|
||||||
{
|
|
||||||
return dbContext.Products
|
|
||||||
.AsAsyncEnumerable();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
[HttpGet]
|
||||||
/// Возвращает продукт по номеру артикула
|
public IAsyncEnumerable<Product> GetProducts()
|
||||||
/// </summary>
|
{
|
||||||
/// <param name="id">Номер артикула</param>
|
return dbContext.Products
|
||||||
/// <returns></returns>
|
.AsAsyncEnumerable();
|
||||||
[HttpGet("{id}")]
|
}
|
||||||
public IEnumerable<Product> GetProduct(string id)
|
|
||||||
{
|
|
||||||
return dbContext.Products
|
|
||||||
.Where(p => p.Id.Equals(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
[HttpGet("{id}")]
|
||||||
/// Загрузка прайс-листа в формате xlsx в базу данных
|
public IEnumerable<Product> GetProduct(string id)
|
||||||
/// </summary>
|
{
|
||||||
/// <returns></returns>
|
return dbContext.Products
|
||||||
[HttpPost]
|
.Where(p => p.Id.Equals(id));
|
||||||
public IActionResult PostProductsFromXls()
|
}
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var products = parser.GetProducts(HttpContext).GroupBy(p => p.ProductSku)
|
|
||||||
.Select(g => new Product(g.Key)
|
|
||||||
{
|
|
||||||
Name = g.First().Name,
|
|
||||||
DeprecatedSkus = g.SelectMany(p => p.DeprecatedSkus).Distinct().ToList(),
|
|
||||||
ProductLines = g.SelectMany(p => p.ProductLines).Distinct().ToList(),
|
|
||||||
IsOnWarehouse = g.Any(p => p.IsOnWarehouse == true),
|
|
||||||
ProductMeasure = g.First().ProductMeasure,
|
|
||||||
DeliveryMakeUp = g.First().DeliveryMakeUp,
|
|
||||||
Price = g.First().Price
|
|
||||||
});
|
|
||||||
|
|
||||||
foreach (var p in products)
|
[HttpPost]
|
||||||
{
|
public IActionResult PostProductsFromXls()
|
||||||
dbContext.Add<Product>(p);
|
{
|
||||||
}
|
try
|
||||||
|
{
|
||||||
|
var products = parser.GetProducts(HttpContext).GroupBy(p => p.ProductSku)
|
||||||
|
.Select(g => new Product(g.Key)
|
||||||
|
{
|
||||||
|
Name = g.First().Name,
|
||||||
|
DeprecatedSkus = g.SelectMany(p => p.DeprecatedSkus).Distinct().ToList(),
|
||||||
|
ProductLines = g.SelectMany(p => p.ProductLines).Distinct().ToList(),
|
||||||
|
IsOnWarehouse = g.Any(p => p.IsOnWarehouse == true),
|
||||||
|
ProductMeasure = g.First().ProductMeasure,
|
||||||
|
DeliveryMakeUp = g.First().DeliveryMakeUp,
|
||||||
|
Price = g.First().Price
|
||||||
|
});
|
||||||
|
|
||||||
dbContext.SaveChanges();
|
foreach (var p in products)
|
||||||
return Ok();
|
{
|
||||||
}
|
dbContext.Add<Product>(p);
|
||||||
catch (Exception ex)
|
}
|
||||||
{
|
|
||||||
return BadRequest(ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
dbContext.SaveChanges();
|
||||||
/// Удаление всех продуктов из базы данных
|
return Ok();
|
||||||
/// </summary>
|
}
|
||||||
/// <returns></returns>
|
catch (Exception ex)
|
||||||
[HttpDelete]
|
{
|
||||||
public IActionResult DeleteAllProducts()
|
return BadRequest(ex.Message);
|
||||||
{
|
}
|
||||||
List<Product> deleted = new();
|
}
|
||||||
if (dbContext.Products.Count() > 0)
|
|
||||||
{
|
[HttpDelete]
|
||||||
foreach (Product p in dbContext.Products)
|
public IActionResult DeleteAllProducts()
|
||||||
{
|
{
|
||||||
deleted.Add(p);
|
List<Product> deleted = new();
|
||||||
dbContext.Remove(p);
|
if (dbContext.Products.Count() > 0)
|
||||||
}
|
{
|
||||||
dbContext.SaveChanges();
|
foreach (Product p in dbContext.Products)
|
||||||
return Ok(deleted);
|
{
|
||||||
}
|
deleted.Add(p);
|
||||||
else return Ok("Empty db");
|
dbContext.Remove(p);
|
||||||
}
|
}
|
||||||
}
|
dbContext.SaveChanges();
|
||||||
|
return Ok(deleted);
|
||||||
|
}
|
||||||
|
else return Ok("Empty db");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -14,11 +14,6 @@ namespace RhSolutions.Api.Controllers
|
|||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Поиск артикула в базе данных через предварительную мультиклассовую классификацию с применением ML-модели артикулов
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="query">Запрос в свободной форме</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IAsyncEnumerable<Product> SearchProducts([FromQuery] string query)
|
public IAsyncEnumerable<Product> SearchProducts([FromQuery] string query)
|
||||||
{
|
{
|
||||||
|
@ -5,8 +5,6 @@ using RhSolutions.Api.Middleware;
|
|||||||
using RhSolutions.QueryModifiers;
|
using RhSolutions.QueryModifiers;
|
||||||
using RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
using RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
||||||
using RhSolutions.QueryModifiers.DrinkingWaterHeatingPipes;
|
using RhSolutions.QueryModifiers.DrinkingWaterHeatingPipes;
|
||||||
using Microsoft.OpenApi.Models;
|
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
@ -62,37 +60,12 @@ builder.Services.AddKeyedTransient<IProductQueryModifier, Sleeve>("Монтаж
|
|||||||
.AddKeyedTransient<IProductQueryModifier, StabilPipe>("Stabil")
|
.AddKeyedTransient<IProductQueryModifier, StabilPipe>("Stabil")
|
||||||
.AddKeyedTransient<IProductQueryModifier, BlackPipe>("Black");
|
.AddKeyedTransient<IProductQueryModifier, BlackPipe>("Black");
|
||||||
|
|
||||||
builder.Services.AddSwaggerGen(options =>
|
|
||||||
{
|
|
||||||
options.SwaggerDoc("v1", new OpenApiInfo
|
|
||||||
{
|
|
||||||
Version = "v1",
|
|
||||||
Title = "RhSolutions API",
|
|
||||||
Description = "API к базе данных артикулов РЕХАУ для поиска с помощью ML.NET и полнотестового поиска PostgreSQL",
|
|
||||||
Contact = new OpenApiContact
|
|
||||||
{
|
|
||||||
Name = "Serghei Cebotari",
|
|
||||||
Url = new Uri("https://cebotari.ru/"),
|
|
||||||
Email = @"serghei@cebotari.ru"
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
|
|
||||||
options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename));
|
|
||||||
});
|
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
app.UseMiddleware<QueryModifier>();
|
app.UseMiddleware<QueryModifier>();
|
||||||
app.UseSwagger().UseSwaggerUI(options =>
|
|
||||||
{
|
|
||||||
options.SwaggerEndpoint("/swagger/v1/swagger.json", "v1");
|
|
||||||
options.RoutePrefix = string.Empty;
|
|
||||||
});
|
|
||||||
|
|
||||||
var context = app.Services.CreateScope().ServiceProvider
|
var context = app.Services.CreateScope().ServiceProvider
|
||||||
.GetRequiredService<RhSolutionsContext>();
|
.GetRequiredService<RhSolutionsContext>();
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
@ -5,8 +5,6 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<UserSecretsId>1c307973-55cf-4d5c-a4f8-1def6b58ee3c</UserSecretsId>
|
<UserSecretsId>1c307973-55cf-4d5c-a4f8-1def6b58ee3c</UserSecretsId>
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
|
||||||
<NoWarn>$(NoWarn);1591</NoWarn>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -21,7 +19,6 @@
|
|||||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />
|
||||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="1.1.0" />
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="1.1.0" />
|
||||||
<PackageReference Include="Rhsolutions.ProductSku" Version="1.0.2" />
|
<PackageReference Include="Rhsolutions.ProductSku" Version="1.0.2" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user