diff --git a/AsbCloudApp/Data/WellSections/WellSectionPlanDto.cs b/AsbCloudApp/Data/ProcessMaps/WellSectionPlanDto.cs
similarity index 82%
rename from AsbCloudApp/Data/WellSections/WellSectionPlanDto.cs
rename to AsbCloudApp/Data/ProcessMaps/WellSectionPlanDto.cs
index 5a17ad44..ba4fc8fb 100644
--- a/AsbCloudApp/Data/WellSections/WellSectionPlanDto.cs
+++ b/AsbCloudApp/Data/ProcessMaps/WellSectionPlanDto.cs
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
-namespace AsbCloudApp.Data.WellSections;
+namespace AsbCloudApp.Data.ProcessMaps;
///
/// Секция скважины - план
@@ -28,26 +28,26 @@ public class WellSectionPlanDto : ItemInfoDto,
/// Начальная глубина бурения, м
///
[Required(ErrorMessage = "Поле обязательно для заполнение")]
- [Range(0, 10000, ErrorMessage = "Допустимое значение от 1 до 10000")]
+ [Range(0, 10000, ErrorMessage = "Допустимое значение от 0 до 10000")]
public double DepthStart { get; set; }
///
/// Конечная глубина бурения, м
///
[Required(ErrorMessage = "Поле обязательно для заполнение")]
- [Range(0, 10000, ErrorMessage = "Допустимое значение от 1 до 10000")]
+ [Range(0, 10000, ErrorMessage = "Допустимое значение от 0 до 10000")]
public double DepthEnd { get; set; }
///
/// Внешний диаметр
///
- [Range(0, 10000, ErrorMessage = "Допустимое значение от 1 до 10000")]
+ [Range(1, 10000, ErrorMessage = "Допустимое значение от 1 до 10000")]
public double? OuterDiameter { get; set; }
///
/// Внутренний диаметр
///
- [Range(0, 10000, ErrorMessage = "Допустимое значение от 1 до 10000")]
+ [Range(1, 10000, ErrorMessage = "Допустимое значение от 1 до 10000")]
public double? InnerDiameter { get; set; }
///
@@ -65,9 +65,5 @@ public class WellSectionPlanDto : ItemInfoDto,
if (OuterDiameter <= InnerDiameter)
yield return new ValidationResult("Внешний диаметр не должен быть больше или равен внутреннему",
new[] { nameof(OuterDiameter) });
-
- if (InnerDiameter >= OuterDiameter)
- yield return new ValidationResult("Внутренний диаметр не должен больше или равен внутреннему",
- new[] { nameof(InnerDiameter) });
}
}
\ No newline at end of file
diff --git a/AsbCloudApp/Services/ValidationResultDto.cs b/AsbCloudApp/Data/ValidationResultDto.cs
similarity index 64%
rename from AsbCloudApp/Services/ValidationResultDto.cs
rename to AsbCloudApp/Data/ValidationResultDto.cs
index a15ab9e5..0116fe0a 100644
--- a/AsbCloudApp/Services/ValidationResultDto.cs
+++ b/AsbCloudApp/Data/ValidationResultDto.cs
@@ -1,6 +1,8 @@
using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
-namespace AsbCloudApp.Services;
+namespace AsbCloudApp.Data;
///
/// Результат валидации объекта
@@ -11,7 +13,7 @@ public class ValidationResultDto
///
/// Флаг валидности
///
- public bool IsValid { get; set; }
+ public bool IsValid => !Warnings.Any();
///
/// Объект валидации
@@ -21,5 +23,5 @@ public class ValidationResultDto
///
/// Предупреждения
///
- public IEnumerable? Warnings { get; set; }
+ public IEnumerable Warnings { get; set; } = Enumerable.Empty();
}
\ No newline at end of file
diff --git a/AsbCloudApp/Repositories/IWellSectionPlanRepository.cs b/AsbCloudApp/Repositories/IWellSectionPlanRepository.cs
new file mode 100644
index 00000000..972fac66
--- /dev/null
+++ b/AsbCloudApp/Repositories/IWellSectionPlanRepository.cs
@@ -0,0 +1,22 @@
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
+using AsbCloudApp.Data;
+using AsbCloudApp.Data.ProcessMaps;
+using AsbCloudApp.Services;
+
+namespace AsbCloudApp.Repositories;
+
+///
+/// Секция скважины - план
+///
+public interface IWellSectionPlanRepository : IRepositoryWellRelated
+{
+ ///
+ /// Получить типы секций
+ ///
+ ///
+ ///
+ ///
+ Task> GetWellSectionTypesAsync(int idWell, CancellationToken cancellationToken);
+}
\ No newline at end of file
diff --git a/AsbCloudApp/Services/ProcessMaps/IProcessMapPlanService.cs b/AsbCloudApp/Services/ProcessMaps/IProcessMapPlanService.cs
index 17273321..2400dddf 100644
--- a/AsbCloudApp/Services/ProcessMaps/IProcessMapPlanService.cs
+++ b/AsbCloudApp/Services/ProcessMaps/IProcessMapPlanService.cs
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
+using AsbCloudApp.Data;
using AsbCloudApp.Data.ProcessMaps;
namespace AsbCloudApp.Services.ProcessMaps;
@@ -12,7 +13,7 @@ public interface IProcessMapPlanService
where T : ProcessMapPlanBaseDto
{
///
- /// Получение РТК по скважине
+ /// Получение РТК план по скважине
///
///
///
diff --git a/AsbCloudApp/Services/WellSections/IWellSectionPlanService.cs b/AsbCloudApp/Services/WellSections/IWellSectionPlanService.cs
deleted file mode 100644
index 599c8509..00000000
--- a/AsbCloudApp/Services/WellSections/IWellSectionPlanService.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-using System.Collections.Generic;
-using System.Threading;
-using System.Threading.Tasks;
-using AsbCloudApp.Data;
-using AsbCloudApp.Data.WellSections;
-
-namespace AsbCloudApp.Services.WellSections;
-
-///
-/// Секция скважины - план
-///
-public interface IWellSectionPlanService
-{
- ///
- /// Добавить секцию
- ///
- ///
- ///
- ///
- Task InsertAsync(WellSectionPlanDto wellSectionPlan, CancellationToken cancellationToken);
-
- ///
- /// Обновить секцию
- ///
- ///
- ///
- ///
- Task UpdateAsync(WellSectionPlanDto wellSectionPlan, CancellationToken cancellationToken);
-
- ///
- /// Получить типы секций
- ///
- ///
- ///
- ///
- Task> GetWellSectionTypesAsync(int idWell, CancellationToken cancellationToken);
-}
\ No newline at end of file
diff --git a/AsbCloudDb/Model/AsbCloudDbContext.cs b/AsbCloudDb/Model/AsbCloudDbContext.cs
index a0fdcede..4b6e339f 100644
--- a/AsbCloudDb/Model/AsbCloudDbContext.cs
+++ b/AsbCloudDb/Model/AsbCloudDbContext.cs
@@ -63,6 +63,8 @@ namespace AsbCloudDb.Model
public virtual DbSet TelemetryWirelineRunOut => Set();
public virtual DbSet TrajectoriesFact => Set();
+
+ public virtual DbSet WellSectionsPlan => Set();
// GTR WITS
public DbSet WitsItemFloat => Set();
@@ -87,7 +89,7 @@ namespace AsbCloudDb.Model
public DbSet Manuals => Set();
public DbSet ManualDirectories => Set();
public DbSet Contacts => Set();
- public DbSet PlanWellSections => Set();
+ public DbSet WellSectionPlans => Set();
public DbSet DrillTests => Set();
public AsbCloudDbContext() : base()
diff --git a/AsbCloudDb/Model/IAsbCloudDbContext.cs b/AsbCloudDb/Model/IAsbCloudDbContext.cs
index adbd6de1..0a1dd91b 100644
--- a/AsbCloudDb/Model/IAsbCloudDbContext.cs
+++ b/AsbCloudDb/Model/IAsbCloudDbContext.cs
@@ -81,7 +81,7 @@ namespace AsbCloudDb.Model
DbSet Contacts { get; }
DbSet DrillTests { get; }
DbSet TrajectoriesFact { get; }
- DbSet PlanWellSections { get; }
+ DbSet WellSectionsPlan { get; }
DatabaseFacade Database { get; }
Task RefreshMaterializedViewAsync(string mwName, CancellationToken token);
diff --git a/AsbCloudInfrastructure/DependencyInjection.cs b/AsbCloudInfrastructure/DependencyInjection.cs
index 0326086e..a07bc70c 100644
--- a/AsbCloudInfrastructure/DependencyInjection.cs
+++ b/AsbCloudInfrastructure/DependencyInjection.cs
@@ -42,13 +42,10 @@ using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using AsbCloudApp.Data.DailyReport.Blocks.TimeBalance;
-using AsbCloudApp.Data.WellSections;
using AsbCloudApp.Services.DailyReport;
-using AsbCloudApp.Services.WellSections;
using AsbCloudDb.Model.DailyReports.Blocks.TimeBalance;
using AsbCloudDb.Model.WellSections;
using AsbCloudInfrastructure.Services.ProcessMaps;
-using AsbCloudInfrastructure.Services.WellSections;
namespace AsbCloudInfrastructure
{
@@ -319,12 +316,13 @@ namespace AsbCloudInfrastructure
services.AddTransient();
services.AddTransient();
services.AddTransient();
-
- services.AddTransient();
+
services.AddTransient, CrudWellRelatedRepositoryBase>();
services.AddTransient, ProcessMapPlanService>();
services.AddTransient, ProcessMapPlanService>();
+
+ services.AddTransient();
return services;
}
diff --git a/AsbCloudInfrastructure/Repository/CrudWellRelatedRepositoryBase.cs b/AsbCloudInfrastructure/Repository/CrudWellRelatedRepositoryBase.cs
index 98d735cb..d788f3d6 100644
--- a/AsbCloudInfrastructure/Repository/CrudWellRelatedRepositoryBase.cs
+++ b/AsbCloudInfrastructure/Repository/CrudWellRelatedRepositoryBase.cs
@@ -25,7 +25,7 @@ namespace AsbCloudInfrastructure.Repository
var entities = await GetQuery()
.Where(e => e.IdWell == idWell)
.AsNoTracking()
- .ToListAsync(token);
+ .ToArrayAsync(token);
var dtos = entities.Select(Convert).ToList();
return dtos;
}
@@ -38,7 +38,7 @@ namespace AsbCloudInfrastructure.Repository
var entities = await GetQuery()
.Where(e => idsWells.Contains(e.IdWell))
.AsNoTracking()
- .ToListAsync(token);
+ .ToArrayAsync(token);
var dtos = entities.Select(Convert).ToList();
return dtos;
}
diff --git a/AsbCloudInfrastructure/Repository/WellSectionPlanRepository.cs b/AsbCloudInfrastructure/Repository/WellSectionPlanRepository.cs
new file mode 100644
index 00000000..f50cd7a0
--- /dev/null
+++ b/AsbCloudInfrastructure/Repository/WellSectionPlanRepository.cs
@@ -0,0 +1,85 @@
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
+using AsbCloudApp.Data;
+using AsbCloudApp.Data.ProcessMaps;
+using AsbCloudApp.Exceptions;
+using AsbCloudApp.Repositories;
+using AsbCloudDb.Model;
+using AsbCloudDb.Model.WellSections;
+using Mapster;
+using Microsoft.EntityFrameworkCore;
+using Npgsql;
+
+namespace AsbCloudInfrastructure.Repository;
+
+public class WellSectionPlanRepository : CrudWellRelatedRepositoryBase,
+ IWellSectionPlanRepository
+{
+ public WellSectionPlanRepository(IAsbCloudDbContext context)
+ : base(context, query => query.Include(w => w.SectionType))
+ {
+ }
+
+ public override async Task InsertAsync(WellSectionPlanDto item, CancellationToken token)
+ {
+ var id = 0;
+
+ try
+ {
+ id = await base.InsertAsync(item, token);
+ }
+ catch (DbUpdateException ex)
+ {
+ if (ex.InnerException is PostgresException pgException)
+ HandlePostgresException(pgException, item);
+ else
+ throw;
+ }
+
+ return id;
+ }
+
+ public override async Task UpdateAsync(WellSectionPlanDto item, CancellationToken token)
+ {
+ var id = 0;
+
+ try
+ {
+ id = await base.UpdateAsync(item, token);
+ }
+ catch (DbUpdateException ex)
+ {
+ if (ex.InnerException is PostgresException pgException)
+ HandlePostgresException(pgException, item);
+ else
+ throw;
+ }
+
+ return id;
+ }
+
+ public async Task> GetWellSectionTypesAsync(int idWell, CancellationToken cancellationToken)
+ {
+ var query = from wellSectionType in dbContext.WellSectionTypes
+ join wellSectionPlan in dbContext.WellSectionsPlan on wellSectionType.Id equals wellSectionPlan.IdSectionType
+ orderby wellSectionType.Order
+ select wellSectionType;
+
+ IEnumerable entities = await query.ToArrayAsync(cancellationToken);
+
+ if (!entities.Any())
+ entities = await dbContext.WellSectionTypes.OrderBy(w => w.Order).ToArrayAsync(cancellationToken);
+
+ return entities.Select(w => w.Adapt());
+ }
+
+ private static void HandlePostgresException(PostgresException pgException, WellSectionPlanDto wellSectionPlan)
+ {
+ if (pgException.SqlState == PostgresErrorCodes.UniqueViolation)
+ throw new ArgumentInvalidException($"Секция уже добавлена в конструкцию скважины",
+ nameof(wellSectionPlan.IdSectionType));
+
+ }
+}
\ No newline at end of file
diff --git a/AsbCloudInfrastructure/Services/ProcessMaps/ProcessMapPlanService.cs b/AsbCloudInfrastructure/Services/ProcessMaps/ProcessMapPlanService.cs
index 58d101ed..e4044310 100644
--- a/AsbCloudInfrastructure/Services/ProcessMaps/ProcessMapPlanService.cs
+++ b/AsbCloudInfrastructure/Services/ProcessMaps/ProcessMapPlanService.cs
@@ -1,10 +1,10 @@
using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data;
using AsbCloudApp.Data.ProcessMaps;
-using AsbCloudApp.Data.WellSections;
using AsbCloudApp.Repositories;
using AsbCloudApp.Services;
using AsbCloudApp.Services.ProcessMaps;
@@ -30,34 +30,35 @@ public class ProcessMapPlanService : IProcessMapPlanService
public async Task>> GetAsync(int idWell, CancellationToken cancellationToken)
{
var wellSectionTypes = await wellSectionTypeRepository.GetAllAsync(cancellationToken);
-
- var planProcessMaps = await processMapPlanRepository.GetByIdWellAsync(idWell, cancellationToken);
- var planWellSections = await wellSectionPlanRepository.GetByIdWellAsync(idWell, cancellationToken);
+ var processMapsPlan = await processMapPlanRepository.GetByIdWellAsync(idWell, cancellationToken);
- return planProcessMaps.Select(processMapPlan =>
+ var wellSectionsPlan = await wellSectionPlanRepository.GetByIdWellAsync(idWell, cancellationToken);
+
+ return processMapsPlan.Select(processMapPlan =>
{
- var planWellSection = planWellSections.SingleOrDefault(s => s.IdSectionType == processMapPlan.IdWellSectionType);
+ var wellSectionPlan = wellSectionsPlan.FirstOrDefault(s => s.IdSectionType == processMapPlan.IdWellSectionType);
- var isValid = planWellSection is not null && planWellSection.DepthStart <= processMapPlan.DepthStart &&
- planWellSection.DepthEnd >= processMapPlan.DepthEnd;
+ var isValid = wellSectionPlan is not null && wellSectionPlan.DepthStart <= processMapPlan.DepthStart &&
+ wellSectionPlan.DepthEnd >= processMapPlan.DepthEnd;
var validationResult = new ValidationResultDto
{
- IsValid = isValid,
Item = processMapPlan
};
- if (isValid)
+ if (isValid)
return validationResult;
-
- var wellSectionType = wellSectionTypes.SingleOrDefault(s => s.Id == processMapPlan.IdWellSectionType);
-
- validationResult.Warnings = new[]
+
+ var wellSectionType = wellSectionTypes.FirstOrDefault(s => s.Id == processMapPlan.IdWellSectionType);
+
+ validationResult.Warnings = new ValidationResult[]
{
- $"Конструкция секции: {wellSectionType?.Caption}; Интервал бурения от {processMapPlan.DepthStart} до {processMapPlan.DepthEnd} не совпадает с данными указанными на странице Конструкция скважины / План"
+ new($"Конструкция секции: {wellSectionType?.Caption}; " +
+ $"Интервал бурения от {processMapPlan.DepthStart} до {processMapPlan.DepthEnd} не совпадает с данными указанными на странице " +
+ $"Конструкция скважины / План")
};
-
+
return validationResult;
});
}
diff --git a/AsbCloudInfrastructure/Services/WellSections/WellSectionPlanService.cs b/AsbCloudInfrastructure/Services/WellSections/WellSectionPlanService.cs
deleted file mode 100644
index 7258f508..00000000
--- a/AsbCloudInfrastructure/Services/WellSections/WellSectionPlanService.cs
+++ /dev/null
@@ -1,68 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading;
-using System.Threading.Tasks;
-using AsbCloudApp.Data;
-using AsbCloudApp.Data.WellSections;
-using AsbCloudApp.Exceptions;
-using AsbCloudApp.Services;
-using AsbCloudApp.Services.WellSections;
-
-namespace AsbCloudInfrastructure.Services.WellSections;
-
-public class WellSectionPlanService : IWellSectionPlanService
-{
- private readonly IRepositoryWellRelated wellSectionPlanRepository;
- private readonly ICrudRepository wellSectionTypeRepository;
-
- public WellSectionPlanService(IRepositoryWellRelated wellSectionPlanRepository,
- ICrudRepository wellSectionTypeRepository)
- {
- this.wellSectionPlanRepository = wellSectionPlanRepository;
- this.wellSectionTypeRepository = wellSectionTypeRepository;
- }
-
- public async Task InsertAsync(WellSectionPlanDto wellSectionPlan, CancellationToken cancellationToken)
- {
- await EnsureUniqueSectionTypeInWellAsync(wellSectionPlan, cancellationToken);
-
- return await wellSectionPlanRepository.InsertAsync(wellSectionPlan, cancellationToken);
- }
-
- public async Task UpdateAsync(WellSectionPlanDto wellSectionPlan, CancellationToken cancellationToken)
- {
- await EnsureUniqueSectionTypeInWellAsync(wellSectionPlan, cancellationToken);
-
- wellSectionPlan.LastUpdateDate = DateTime.UtcNow;
-
- return await wellSectionPlanRepository.UpdateAsync(wellSectionPlan, cancellationToken);
- }
-
- public async Task> GetWellSectionTypesAsync(int idWell, CancellationToken cancellationToken)
- {
- var wellSectionTypes = (await wellSectionTypeRepository.GetAllAsync(cancellationToken))
- .OrderBy(w => w.Order);
-
- var planWellSections = await wellSectionPlanRepository.GetByIdWellAsync(idWell, cancellationToken);
-
- if (!planWellSections.Any())
- return wellSectionTypes;
-
- return wellSectionTypes.Where(w => planWellSections.Any(s => s.IdSectionType == w.Id));
- }
-
- private async Task EnsureUniqueSectionTypeInWellAsync(WellSectionPlanDto section, CancellationToken cancellationToken)
- {
- var existingWellSectionPlan = (await wellSectionPlanRepository.GetByIdWellAsync(section.IdWell, cancellationToken))
- .SingleOrDefault(s => s.IdSectionType == section.IdSectionType);
-
- if (existingWellSectionPlan is not null && existingWellSectionPlan.Id != section.Id)
- {
- var sectionType = await wellSectionTypeRepository.GetOrDefaultAsync(section.IdSectionType, cancellationToken);
-
- throw new ArgumentInvalidException($"Секция '{sectionType?.Caption}' уже добавлена в конструкцию скважины",
- nameof(section.IdSectionType));
- }
- }
-}
\ No newline at end of file
diff --git a/AsbCloudWebApi.Tests/UnitTests/Services/ProcessMaps/ProcessMapPlanServiceTests.cs b/AsbCloudWebApi.Tests/UnitTests/Services/ProcessMaps/ProcessMapPlanServiceTests.cs
index 0981e29f..17d96d81 100644
--- a/AsbCloudWebApi.Tests/UnitTests/Services/ProcessMaps/ProcessMapPlanServiceTests.cs
+++ b/AsbCloudWebApi.Tests/UnitTests/Services/ProcessMaps/ProcessMapPlanServiceTests.cs
@@ -4,7 +4,6 @@ using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data;
using AsbCloudApp.Data.ProcessMaps;
-using AsbCloudApp.Data.WellSections;
using AsbCloudApp.Repositories;
using AsbCloudApp.Services;
using AsbCloudInfrastructure.Services.ProcessMaps;
diff --git a/AsbCloudWebApi.Tests/UnitTests/Services/WellSections/WellSectionPlanServiceTests.cs b/AsbCloudWebApi.Tests/UnitTests/Services/WellSections/WellSectionPlanServiceTests.cs
deleted file mode 100644
index f5a2edad..00000000
--- a/AsbCloudWebApi.Tests/UnitTests/Services/WellSections/WellSectionPlanServiceTests.cs
+++ /dev/null
@@ -1,169 +0,0 @@
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading;
-using System.Threading.Tasks;
-using AsbCloudApp.Data;
-using AsbCloudApp.Data.WellSections;
-using AsbCloudApp.Exceptions;
-using AsbCloudApp.Services;
-using AsbCloudInfrastructure.Services.WellSections;
-using NSubstitute;
-using Xunit;
-
-namespace AsbCloudWebApi.Tests.UnitTests.Services.WellSections;
-
-public class WellSectionPlanServiceTests
-{
- private const int idWellSectionPlan = 1;
- private const int idWell = 3;
- private const int idWellSectionType = 54;
-
- private readonly IEnumerable fakePlanWellSections = new WellSectionPlanDto[]
- {
- new()
- {
- Id = idWellSectionPlan,
- IdWell = idWell,
- IdSectionType = idWellSectionType
- }
- };
-
- private readonly IEnumerable fakeWellSectionTypes = new WellSectionTypeDto[]
- {
- new()
- {
- Id = idWellSectionType
- }
- };
-
- private readonly IRepositoryWellRelated wellSectionPlanRepositoryMock =
- Substitute.For>();
-
- private readonly ICrudRepository wellSectionTypeRepositoryMock =
- Substitute.For>();
-
- private readonly WellSectionPlanService wellSectionPlanService;
-
- public WellSectionPlanServiceTests()
- {
- wellSectionPlanService = new WellSectionPlanService(wellSectionPlanRepositoryMock, wellSectionTypeRepositoryMock);
-
- wellSectionTypeRepositoryMock.GetAllAsync(Arg.Any())
- .ReturnsForAnyArgs(fakeWellSectionTypes);
- }
-
- [Fact]
- public async Task InsertAsync_InsertNewWellSectionTypeWithUniqueSectionTypeInWell_InvokesWellSectionPlanRepositoryInsertAsync()
- {
- //arrange
- var insertedWellSection = new WellSectionPlanDto();
-
- //act
- await wellSectionPlanService.InsertAsync(insertedWellSection, CancellationToken.None);
-
- //assert
- await wellSectionPlanRepositoryMock.Received().InsertAsync(Arg.Any(), Arg.Any());
- }
-
- [Fact]
- public async Task InsertAsync_InsertNewWellSectionTypeWithNotUniqueSectionTypeInWell_ReturnsDuplicateException()
- {
- //arrange
- var insertedWellSection = new WellSectionPlanDto
- {
- Id = 2,
- IdSectionType = idWellSectionType
- };
-
- wellSectionPlanRepositoryMock.GetByIdWellAsync(Arg.Any(), Arg.Any())
- .ReturnsForAnyArgs(fakePlanWellSections);
-
- //act
- Task Result() => wellSectionPlanService.InsertAsync(insertedWellSection, CancellationToken.None);
-
- //assert
- await Assert.ThrowsAsync(Result);
- }
-
- [Fact]
- public async Task UpdateAsync_UpdateExistingWellSectionTypeWithUniqueSectionTypeInWell_InvokesWellSectionPlanRepositoryUpdateAsync()
- {
- //arrange
- var updatedWellSection = new WellSectionPlanDto
- {
- Id = idWellSectionPlan,
- IdSectionType = idWellSectionType
- };
-
- //act
- await wellSectionPlanService.UpdateAsync(updatedWellSection, CancellationToken.None);
-
- //assert
- await wellSectionPlanRepositoryMock.Received().UpdateAsync(Arg.Any(), Arg.Any());
- }
-
- [Fact]
- public async Task UpdateAsync_ReturnsLastUpdateDateNotNull()
- {
- //arrange
- var updatedWellSection = new WellSectionPlanDto
- {
- Id = idWellSectionPlan,
- IdSectionType = idWellSectionType
- };
-
- //act
- await wellSectionPlanService.UpdateAsync(updatedWellSection, CancellationToken.None);
-
- //assert
- Assert.NotNull(updatedWellSection.LastUpdateDate);
- }
-
- [Fact]
- public async Task UpdateAsync_UpdateExistingWellSectionTypeWithNotUniqueSectionTypeInWell_ReturnsDuplicateException()
- {
- //arrange
- var updatedWellSection = new WellSectionPlanDto
- {
- Id = 2,
- IdSectionType = idWellSectionType
- };
-
- wellSectionPlanRepositoryMock.GetByIdWellAsync(Arg.Any(), Arg.Any())
- .ReturnsForAnyArgs(fakePlanWellSections);
-
- //act
- Task Result() => wellSectionPlanService.UpdateAsync(updatedWellSection, CancellationToken.None);
-
- //assert
- await Assert.ThrowsAsync(Result);
- }
-
- [Fact]
- public async Task GetWellSectionTypesAsync_EmptyCollectionWellSectionPlan_ReturnsCollectionWellSectionType()
- {
- //arrange
- wellSectionPlanRepositoryMock.GetByIdWellAsync(Arg.Any(), Arg.Any())
- .ReturnsForAnyArgs(Enumerable.Empty());
-
- //act
- var result = await wellSectionPlanService.GetWellSectionTypesAsync(idWell, CancellationToken.None);
-
- //assert
- Assert.Single(result);
- }
-
- [Fact]
- public async Task GetWellSectionTypesAsync_NotEmptyCollectionWellSectionPlan_ReturnsCollectionWellSectionType()
- {
- //arrange
- wellSectionPlanRepositoryMock.GetByIdWellAsync(Arg.Any(), Arg.Any())
- .ReturnsForAnyArgs(fakePlanWellSections);
-
- //act
- var result = await wellSectionPlanService.GetWellSectionTypesAsync(idWell, CancellationToken.None);
-
- //assert
- Assert.Single(result);
- }
-}
\ No newline at end of file
diff --git a/AsbCloudWebApi/Controllers/WellSections/WellSectionPlanController.cs b/AsbCloudWebApi/Controllers/ProcessMaps/WellSectionPlanController.cs
similarity index 88%
rename from AsbCloudWebApi/Controllers/WellSections/WellSectionPlanController.cs
rename to AsbCloudWebApi/Controllers/ProcessMaps/WellSectionPlanController.cs
index 3fd21c68..454aea70 100644
--- a/AsbCloudWebApi/Controllers/WellSections/WellSectionPlanController.cs
+++ b/AsbCloudWebApi/Controllers/ProcessMaps/WellSectionPlanController.cs
@@ -1,18 +1,18 @@
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data;
using AsbCloudApp.Data.ProcessMaps;
-using AsbCloudApp.Data.WellSections;
using AsbCloudApp.Exceptions;
+using AsbCloudApp.Repositories;
using AsbCloudApp.Services;
-using AsbCloudApp.Services.WellSections;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
-namespace AsbCloudWebApi.Controllers.WellSections;
+namespace AsbCloudWebApi.Controllers.ProcessMaps;
///
/// Конструкция скважины - план
@@ -22,20 +22,17 @@ namespace AsbCloudWebApi.Controllers.WellSections;
[Authorize]
public class WellSectionPlanController : ControllerBase
{
- private readonly IWellSectionPlanService wellSectionPlanService;
private readonly IWellService wellService;
+ private readonly IWellSectionPlanRepository wellSectionPlanRepository;
private readonly ICrudRepository wellSectionRepository;
- private readonly IRepositoryWellRelated wellSectionPlanRepository;
- public WellSectionPlanController(IWellSectionPlanService wellSectionPlanService,
- IWellService wellService,
- ICrudRepository wellSectionRepository,
- IRepositoryWellRelated wellSectionPlanRepository)
+ public WellSectionPlanController(IWellService wellService,
+ IWellSectionPlanRepository wellSectionPlanRepository,
+ ICrudRepository wellSectionRepository)
{
- this.wellSectionPlanService = wellSectionPlanService;
this.wellService = wellService;
- this.wellSectionRepository = wellSectionRepository;
this.wellSectionPlanRepository = wellSectionPlanRepository;
+ this.wellSectionRepository = wellSectionRepository;
}
//TODO: так же следует вынести в базовый контроллер
@@ -73,7 +70,7 @@ public class WellSectionPlanController : ControllerBase
await AssertUserAccessToWell(idWell, cancellationToken);
- var wellSectionId = await wellSectionPlanService.InsertAsync(wellSection, cancellationToken);
+ var wellSectionId = await wellSectionPlanRepository.InsertAsync(wellSection, cancellationToken);
return Ok(wellSectionId);
}
@@ -94,12 +91,13 @@ public class WellSectionPlanController : ControllerBase
{
wellSection.IdWell = idWell;
wellSection.IdUser = IdUser;
-
+ wellSection.LastUpdateDate = DateTimeOffset.UtcNow;
+
await CheckIsExistsWellSectionTypeAsync(wellSection.IdSectionType, cancellationToken);
await AssertUserAccessToWell(idWell, cancellationToken);
- var wellSectionId = await wellSectionPlanService.UpdateAsync(wellSection, cancellationToken);
+ var wellSectionId = await wellSectionPlanRepository.UpdateAsync(wellSection, cancellationToken);
if (wellSectionId == ICrudRepository.ErrorIdNotFound)
return this.ValidationBadRequest(nameof(wellSection.Id), $"Секции скважины с Id: {wellSection.Id} не существует");
@@ -121,7 +119,7 @@ public class WellSectionPlanController : ControllerBase
{
await AssertUserAccessToWell(idWell, cancellationToken);
- var wellSectionTypes = await wellSectionPlanService.GetWellSectionTypesAsync(idWell, cancellationToken);
+ var wellSectionTypes = await wellSectionPlanRepository.GetWellSectionTypesAsync(idWell, cancellationToken);
if (!wellSectionTypes.Any())
return NoContent();