Compare commits
No commits in common. "c13e92da1c04cfa0383efd9421bb18f1e979371f" and "29d70967861e32ad8c67adcd9bdc19fc018325ef" have entirely different histories.
c13e92da1c
...
29d7096786
12
Dockerfile
12
Dockerfile
@ -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
|
WORKDIR /source
|
||||||
COPY . .
|
COPY . .
|
||||||
|
RUN dotnet restore
|
||||||
RUN dotnet publish --property:OutputPath=/app
|
RUN dotnet publish --property:OutputPath=/app
|
||||||
|
|
||||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine
|
FROM mcr.microsoft.com/dotnet/aspnet:8.0-jammy-chiseled
|
||||||
EXPOSE 8080
|
EXPOSE 5000
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=build /app .
|
COPY --from=build /app .
|
||||||
USER $APP_UID
|
ENV ASPNETCORE_ENVIRONMENT Production
|
||||||
|
ENTRYPOINT ["./RhSolutions.Api", "--urls=http://0.0.0.0:5000"]
|
||||||
ENTRYPOINT ["./RhSolutions.Api"]
|
|
@ -16,7 +16,7 @@ namespace RhSolutions.Api.Controllers
|
|||||||
this.dbContext = dbContext;
|
this.dbContext = dbContext;
|
||||||
this.parser = parser;
|
this.parser = parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Возвращает все продукты в базе данных
|
/// Возвращает все продукты в базе данных
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -50,9 +50,7 @@ namespace RhSolutions.Api.Controllers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var file = Request.Form.Files.FirstOrDefault();
|
var products = parser.GetProducts(HttpContext).GroupBy(p => p.ProductSku)
|
||||||
var products = parser.GetProducts(file)
|
|
||||||
.GroupBy(p => p.ProductSku)
|
|
||||||
.Select(g => new Product(g.Key)
|
.Select(g => new Product(g.Key)
|
||||||
{
|
{
|
||||||
Name = g.First().Name,
|
Name = g.First().Name,
|
||||||
@ -64,7 +62,11 @@ namespace RhSolutions.Api.Controllers
|
|||||||
Price = g.First().Price
|
Price = g.First().Price
|
||||||
});
|
});
|
||||||
|
|
||||||
dbContext.AddRange(products);
|
foreach (var p in products)
|
||||||
|
{
|
||||||
|
dbContext.Add<Product>(p);
|
||||||
|
}
|
||||||
|
|
||||||
dbContext.SaveChanges();
|
dbContext.SaveChanges();
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
"anonymousAuthentication": true,
|
"anonymousAuthentication": true,
|
||||||
"launchBrowser": false,
|
"launchBrowser": false,
|
||||||
"iisExpress": {
|
"iisExpress": {
|
||||||
"applicationUrl": "http://localhost:8080",
|
"applicationUrl": "http://localhost:5000",
|
||||||
"sslPort": 0
|
"sslPort": 0
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -13,7 +13,7 @@
|
|||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"dotnetRunMessages": true,
|
"dotnetRunMessages": true,
|
||||||
"launchBrowser": false,
|
"launchBrowser": false,
|
||||||
"applicationUrl": "http://localhost:8080",
|
"applicationUrl": "http://localhost:5000",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
}
|
}
|
||||||
|
@ -5,22 +5,31 @@ namespace RhSolutions.Api.Services
|
|||||||
{
|
{
|
||||||
public class ClosedXMLParser : IPricelistParser
|
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;
|
if (context == null)
|
||||||
}
|
|
||||||
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 _))
|
|
||||||
{
|
{
|
||||||
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)
|
private IXLTable GetTable(XLWorkbook wb)
|
||||||
|
@ -4,6 +4,6 @@ namespace RhSolutions.Api.Services
|
|||||||
{
|
{
|
||||||
public interface IPricelistParser
|
public interface IPricelistParser
|
||||||
{
|
{
|
||||||
public IEnumerable<Product> GetProducts(IFormFile? file);
|
public List<Product> GetProducts(HttpContext context);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,7 +7,6 @@ public class RautitanPipesTests : ProductParsersTests
|
|||||||
[TestCase("Труба flex 16", "Труба РЕХАУ FLEX 16x2,2")]
|
[TestCase("Труба flex 16", "Труба РЕХАУ FLEX 16x2,2")]
|
||||||
[TestCase("Унив.труба RAUTITAN flex 32x4,4, прям.отрезки 6м", "Труба РЕХАУ FLEX 32x4,4")]
|
[TestCase("Унив.труба RAUTITAN flex 32x4,4, прям.отрезки 6м", "Труба РЕХАУ FLEX 32x4,4")]
|
||||||
[TestCase("Труба flex 32", "Труба РЕХАУ 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)
|
public void FlexPipeTest(string query, string modified)
|
||||||
=> Invoke(productType: "Flex", query, modified);
|
=> Invoke(productType: "Flex", query, modified);
|
||||||
|
|
||||||
|
@ -4,13 +4,14 @@ services:
|
|||||||
build: .
|
build: .
|
||||||
container_name: app
|
container_name: app
|
||||||
ports:
|
ports:
|
||||||
- 8080:8080
|
- 5000:5000
|
||||||
environment:
|
environment:
|
||||||
- DB_HOST=db
|
- DB_HOST=db
|
||||||
- DB_PORT=5432
|
- DB_PORT=5432
|
||||||
- DB_DATABASE=rhsolutions
|
- DB_DATABASE=rhsolutions
|
||||||
- DB_USER=chebser
|
- DB_USER=chebser
|
||||||
- DB_PASSWORD=Rehau-987
|
- DB_PASSWORD=Rehau-987
|
||||||
|
- ASPNETCORE_ENVIRONMENT=Development
|
||||||
networks:
|
networks:
|
||||||
- rhsolutions
|
- rhsolutions
|
||||||
volumes:
|
volumes:
|
||||||
|
Loading…
Reference in New Issue
Block a user