0
0

Compare commits

...

2 Commits

Author SHA1 Message Date
27dd2af627 Add API documentation 2024-01-14 23:03:52 +03:00
0452f379c6 Add basic swagger support 2024-01-14 16:03:42 +03:00
4 changed files with 121 additions and 69 deletions

View File

@ -17,6 +17,10 @@ namespace RhSolutions.Api.Controllers
this.parser = parser;
}
/// <summary>
/// Возвращает все продукты в базе данных
/// </summary>
/// <returns></returns>
[HttpGet]
public IAsyncEnumerable<Product> GetProducts()
{
@ -24,6 +28,11 @@ namespace RhSolutions.Api.Controllers
.AsAsyncEnumerable();
}
/// <summary>
/// Возвращает продукт по номеру артикула
/// </summary>
/// <param name="id">Номер артикула</param>
/// <returns></returns>
[HttpGet("{id}")]
public IEnumerable<Product> GetProduct(string id)
{
@ -31,6 +40,10 @@ namespace RhSolutions.Api.Controllers
.Where(p => p.Id.Equals(id));
}
/// <summary>
/// Загрузка прайс-листа в формате xlsx в базу данных
/// </summary>
/// <returns></returns>
[HttpPost]
public IActionResult PostProductsFromXls()
{
@ -62,6 +75,10 @@ namespace RhSolutions.Api.Controllers
}
}
/// <summary>
/// Удаление всех продуктов из базы данных
/// </summary>
/// <returns></returns>
[HttpDelete]
public IActionResult DeleteAllProducts()
{

View File

@ -14,6 +14,11 @@ namespace RhSolutions.Api.Controllers
this.context = context;
}
/// <summary>
/// Поиск артикула в базе данных через предварительную мультиклассовую классификацию с применением ML-модели артикулов
/// </summary>
/// <param name="query">Запрос в свободной форме</param>
/// <returns></returns>
[HttpGet]
public IAsyncEnumerable<Product> SearchProducts([FromQuery] string query)
{

View File

@ -5,6 +5,8 @@ using RhSolutions.Api.Middleware;
using RhSolutions.QueryModifiers;
using RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
using RhSolutions.QueryModifiers.DrinkingWaterHeatingPipes;
using Microsoft.OpenApi.Models;
using System.Reflection;
var builder = WebApplication.CreateBuilder(args);
@ -60,10 +62,35 @@ builder.Services.AddKeyedTransient<IProductQueryModifier, Sleeve>("Монтаж
.AddKeyedTransient<IProductQueryModifier, StabilPipe>("Stabil")
.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();
app.MapControllers();
app.UseMiddleware<QueryModifier>();
app.UseSwagger().UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "v1");
options.RoutePrefix = string.Empty;
});
var context = app.Services.CreateScope().ServiceProvider
.GetRequiredService<RhSolutionsContext>();

View File

@ -5,6 +5,8 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>1c307973-55cf-4d5c-a4f8-1def6b58ee3c</UserSecretsId>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>
<ItemGroup>
@ -19,6 +21,7 @@
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="1.1.0" />
<PackageReference Include="Rhsolutions.ProductSku" Version="1.0.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>
<ItemGroup>