0
0

Compare commits

...

4 Commits

Author SHA1 Message Date
c13e92da1c Fix environment variable
Some checks failed
Test and release / test (push) Failing after 2m52s
Test and release / release-image (push) Successful in 6m20s
2024-08-26 13:51:33 +03:00
c7e27eb6c6 Change build image 2024-08-26 13:51:05 +03:00
a359344395 Change port 2024-08-26 13:50:42 +03:00
0276a77b32 Send files in Form 2024-08-08 16:38:23 +03:00
7 changed files with 28 additions and 39 deletions

View File

@ -1,12 +1,12 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0-jammy AS build FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine 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-jammy-chiseled FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine
EXPOSE 5000 EXPOSE 8080
WORKDIR /app WORKDIR /app
COPY --from=build /app . COPY --from=build /app .
ENV ASPNETCORE_ENVIRONMENT Production USER $APP_UID
ENTRYPOINT ["./RhSolutions.Api", "--urls=http://0.0.0.0:5000"]
ENTRYPOINT ["./RhSolutions.Api"]

View File

@ -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,7 +50,9 @@ namespace RhSolutions.Api.Controllers
{ {
try try
{ {
var products = parser.GetProducts(HttpContext).GroupBy(p => p.ProductSku) var file = Request.Form.Files.FirstOrDefault();
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,
@ -62,11 +64,7 @@ namespace RhSolutions.Api.Controllers
Price = g.First().Price Price = g.First().Price
}); });
foreach (var p in products) dbContext.AddRange(products);
{
dbContext.Add<Product>(p);
}
dbContext.SaveChanges(); dbContext.SaveChanges();
return Ok(); return Ok();
} }

View File

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

View File

@ -5,31 +5,22 @@ namespace RhSolutions.Api.Services
{ {
public class ClosedXMLParser : IPricelistParser public class ClosedXMLParser : IPricelistParser
{ {
public List<Product> GetProducts(HttpContext context) public IEnumerable<Product> GetProducts(IFormFile? file)
{ {
using (var memoryStream = new MemoryStream()) if (file == null)
{ {
if (context == null) 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 _))
{ {
return new List<Product>(); yield return ParseRow(row);
} }
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)

View File

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

View File

@ -7,6 +7,7 @@ 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);

View File

@ -4,14 +4,13 @@ services:
build: . build: .
container_name: app container_name: app
ports: ports:
- 5000:5000 - 8080:8080
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: