0
0

Compare commits

..

No commits in common. "c13e92da1c04cfa0383efd9421bb18f1e979371f" and "29d70967861e32ad8c67adcd9bdc19fc018325ef" have entirely different histories.

7 changed files with 39 additions and 28 deletions

View File

@ -1,12 +1,12 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
FROM mcr.microsoft.com/dotnet/sdk:8.0-jammy AS build
WORKDIR /source
COPY . .
RUN dotnet restore
RUN dotnet publish --property:OutputPath=/app
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine
EXPOSE 8080
FROM mcr.microsoft.com/dotnet/aspnet:8.0-jammy-chiseled
EXPOSE 5000
WORKDIR /app
COPY --from=build /app .
USER $APP_UID
ENTRYPOINT ["./RhSolutions.Api"]
ENV ASPNETCORE_ENVIRONMENT Production
ENTRYPOINT ["./RhSolutions.Api", "--urls=http://0.0.0.0:5000"]

View File

@ -16,7 +16,7 @@ namespace RhSolutions.Api.Controllers
this.dbContext = dbContext;
this.parser = parser;
}
/// <summary>
/// Возвращает все продукты в базе данных
/// </summary>
@ -50,9 +50,7 @@ namespace RhSolutions.Api.Controllers
{
try
{
var file = Request.Form.Files.FirstOrDefault();
var products = parser.GetProducts(file)
.GroupBy(p => p.ProductSku)
var products = parser.GetProducts(HttpContext).GroupBy(p => p.ProductSku)
.Select(g => new Product(g.Key)
{
Name = g.First().Name,
@ -64,7 +62,11 @@ namespace RhSolutions.Api.Controllers
Price = g.First().Price
});
dbContext.AddRange(products);
foreach (var p in products)
{
dbContext.Add<Product>(p);
}
dbContext.SaveChanges();
return Ok();
}

View File

@ -4,7 +4,7 @@
"anonymousAuthentication": true,
"launchBrowser": false,
"iisExpress": {
"applicationUrl": "http://localhost:8080",
"applicationUrl": "http://localhost:5000",
"sslPort": 0
}
},
@ -13,7 +13,7 @@
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "http://localhost:8080",
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}

View File

@ -5,22 +5,31 @@ namespace RhSolutions.Api.Services
{
public class ClosedXMLParser : IPricelistParser
{
public IEnumerable<Product> GetProducts(IFormFile? file)
public List<Product> GetProducts(HttpContext context)
{
if (file == null)
using (var memoryStream = new MemoryStream())
{
yield break;
}
using XLWorkbook wb = new XLWorkbook(file.OpenReadStream());
var table = GetTable(wb);
var rows = table.DataRange.Rows();
foreach (var row in rows)
{
if (ProductSku.TryParse(row.Field("Актуальный материал")
.GetString(), out _))
if (context == null)
{
yield return ParseRow(row);
return new List<Product>();
}
context.Request.Body.CopyToAsync(memoryStream).GetAwaiter().GetResult();
List<Product> products = new();
using (var wb = new XLWorkbook(memoryStream))
{
var table = GetTable(wb);
var rows = table.DataRange.Rows();
foreach (var row in rows)
{
if (ProductSku.TryParse(row.Field("Актуальный материал")
.GetString(), out _))
{
products.Add(ParseRow(row));
}
}
}
return products;
}
}
private IXLTable GetTable(XLWorkbook wb)

View File

@ -4,6 +4,6 @@ namespace RhSolutions.Api.Services
{
public interface IPricelistParser
{
public IEnumerable<Product> GetProducts(IFormFile? file);
public List<Product> GetProducts(HttpContext context);
}
}

View File

@ -7,7 +7,6 @@ public class RautitanPipesTests : ProductParsersTests
[TestCase("Труба flex 16", "Труба РЕХАУ FLEX 16x2,2")]
[TestCase("Унив.труба RAUTITAN flex 32x4,4, прям.отрезки 6м", "Труба РЕХАУ FLEX 32x4,4")]
[TestCase("Труба flex 32", "Труба РЕХАУ FLEX 32x4,4")]
[TestCase("20 Труба PPRC SDR6 PN20 Дн32х5,4 ГОСТ 32415-2013 heisskraft м 10,0", "Труба РЕХАУ FLEX 32x4,4")]
public void FlexPipeTest(string query, string modified)
=> Invoke(productType: "Flex", query, modified);

View File

@ -4,13 +4,14 @@ services:
build: .
container_name: app
ports:
- 8080:8080
- 5000:5000
environment:
- DB_HOST=db
- DB_PORT=5432
- DB_DATABASE=rhsolutions
- DB_USER=chebser
- DB_PASSWORD=Rehau-987
- ASPNETCORE_ENVIRONMENT=Development
networks:
- rhsolutions
volumes: