From 97e01be7dba1b79594204bcd729cfc0c09fb6f82 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Mon, 19 Feb 2024 13:14:58 +0500 Subject: [PATCH] WellOperationController remove validation by dates gap between operations --- .../Repositories/IWellOperationRepository.cs | 15 --- .../Repository/WellOperationRepository.cs | 58 ------------ .../WellOperationControllerTest.cs | 94 ------------------- .../Controllers/WellOperationController.cs | 29 ------ 4 files changed, 196 deletions(-) diff --git a/AsbCloudApp/Repositories/IWellOperationRepository.cs b/AsbCloudApp/Repositories/IWellOperationRepository.cs index 33fbf1f5..2ac586aa 100644 --- a/AsbCloudApp/Repositories/IWellOperationRepository.cs +++ b/AsbCloudApp/Repositories/IWellOperationRepository.cs @@ -118,21 +118,6 @@ namespace AsbCloudApp.Repositories /// Task GetDatesRangeAsync(int idWell, int idType, CancellationToken cancellationToken); - /// - /// Валидация данных - /// - /// - /// - IEnumerable Validate(IEnumerable wellOperations); - - /// - /// Валидация данных (проверка с базой) - /// - /// - /// - /// - Task> ValidateWithDbAsync(IEnumerable wellOperations, CancellationToken cancellationToken); - /// /// Удаление полных дубликатов операций по всем скважинам /// diff --git a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs index 2af1127e..00349a6c 100644 --- a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs +++ b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs @@ -4,10 +4,6 @@ using AsbCloudApp.Requests; using AsbCloudApp.Services; using AsbCloudDb; using AsbCloudDb.Model; -using DocumentFormat.OpenXml.Spreadsheet; -using DocumentFormat.OpenXml.Vml; -using DocumentFormat.OpenXml.Wordprocessing; -using Irony.Parsing; using Mapster; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Caching.Memory; @@ -21,7 +17,6 @@ using System.Threading.Tasks; namespace AsbCloudInfrastructure.Repository; - /// /// репозиторий операций по скважине /// @@ -326,59 +321,6 @@ public class WellOperationRepository : IWellOperationRepository return dtos; } - public async Task> ValidateWithDbAsync(IEnumerable wellOperationDtos, CancellationToken token) - { - var firstOperation = wellOperationDtos - .FirstOrDefault(); - - if (firstOperation is null) - return Enumerable.Empty(); - - var request = new WellOperationRequest() - { - IdWell = firstOperation.IdWell, - OperationType = firstOperation.IdType, - }; - - var entities = await BuildQuery(request) - .AsNoTracking() - .ToArrayAsync(token); - - var wellOperationsUnion = entities.Union(wellOperationDtos).OrderBy(o => o.DateStart); - - var results = Validate(wellOperationsUnion); - return results; - } - - public IEnumerable Validate(IEnumerable wellOperationDtos) - { - var enumerator = wellOperationDtos.OrderBy(o => o.DateStart) - .GetEnumerator(); - - if (!enumerator.MoveNext()) - yield break; - - var previous = enumerator.Current; - - while(enumerator.MoveNext()) - { - var current = enumerator.Current; - var previousDateStart = previous.DateStart.ToUniversalTime(); - var currentDateStart = current.DateStart.ToUniversalTime(); - - var previousDateEnd = previous.DateStart.AddHours(previous.DurationHours).ToUniversalTime(); - - if (previousDateStart.AddDays(Gap) < currentDateStart) - { - yield return new ValidationResult( - "Разница дат между операциями не должна превышать 90 дней", - new[] { nameof(wellOperationDtos) }); - } - - previous = current; - } - } - /// public async Task InsertRangeAsync( IEnumerable wellOperationDtos, diff --git a/AsbCloudWebApi.IntegrationTests/Controllers/WellOperationControllerTest.cs b/AsbCloudWebApi.IntegrationTests/Controllers/WellOperationControllerTest.cs index a5e0064a..46ce1d4d 100644 --- a/AsbCloudWebApi.IntegrationTests/Controllers/WellOperationControllerTest.cs +++ b/AsbCloudWebApi.IntegrationTests/Controllers/WellOperationControllerTest.cs @@ -36,56 +36,6 @@ public class WellOperationControllerTest : BaseIntegrationTest } }; - private readonly WellOperationDto[] dtosWithError = new WellOperationDto[] - { - new() - { - Id = 3, - IdWell = idWell, - IdType = 1, - DateStart = DateTimeOffset.Now, - CategoryInfo = "1", - CategoryName = "1", - Comment = "1", - Day = 1, - DepthEnd = 20, - DepthStart = 10, - DurationHours = 1, - IdCategory = 5000, - IdParentCategory = null, - IdPlan = null, - IdUser = 1, - IdWellSectionType = 1, - LastUpdateDate = DateTimeOffset.Now, - NptHours = 1, - WellSectionTypeName = null, - UserName = null - }, - new() - { - Id = 4, - IdWell = idWell, - IdType = 1, - DateStart = DateTimeOffset.Now.AddDays(1000), - CategoryInfo = "1", - CategoryName = "1", - Comment = "1", - Day = 1, - DepthEnd = 20, - DepthStart = 10, - DurationHours = 1, - IdCategory = 5000, - IdParentCategory = null, - IdPlan = null, - IdUser = 1, - IdWellSectionType = 1, - LastUpdateDate = DateTimeOffset.Now, - NptHours = 1, - WellSectionTypeName = null, - UserName = null - } - }; - private IWellOperationClient client; public WellOperationControllerTest(WebAppFactoryFixture factory) @@ -109,21 +59,6 @@ public class WellOperationControllerTest : BaseIntegrationTest Assert.Equal(HttpStatusCode.OK, response.StatusCode); } - - /// - /// Неуспешное добавление операций (без предварительной очистки данных) - /// - /// - [Fact] - public async Task InsertRange_returns_error() - { - //act - var response = await client.InsertRangeAsync(idWell, 1, false, dtosWithError); - - //assert - Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); - } - /// /// Успешное добавление операций (с предварительной очисткой данных) /// @@ -138,20 +73,6 @@ public class WellOperationControllerTest : BaseIntegrationTest Assert.Equal(HttpStatusCode.OK, response.StatusCode); } - /// - /// Неуспешное добавление операций (с предварительной очисткой данных) - /// - /// - [Fact] - public async Task InsertRangeWithDeleteBefore_returns_error() - { - //act - var response = await client.InsertRangeAsync(idWell, 1, true, dtosWithError); - - //assert - Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); - } - /// /// Успешное обновление операции /// @@ -166,21 +87,6 @@ public class WellOperationControllerTest : BaseIntegrationTest //assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); } - - /// - /// Неуспешное обновление операции - /// - /// - [Fact] - public async Task UpdateAsync_returns_error() - { - //act - var dto = dtosWithError.LastOrDefault()!; - var response = await client.UpdateAsync(idWell, 1, dto, CancellationToken.None); - - //assert - Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); - } /// /// Получение плановых операций diff --git a/AsbCloudWebApi/Controllers/WellOperationController.cs b/AsbCloudWebApi/Controllers/WellOperationController.cs index b9b99dc8..83f2987a 100644 --- a/AsbCloudWebApi/Controllers/WellOperationController.cs +++ b/AsbCloudWebApi/Controllers/WellOperationController.cs @@ -236,10 +236,6 @@ namespace AsbCloudWebApi.Controllers wellOperation.IdUser = User.GetUserId(); wellOperation.IdType = idType; - var validationResult = await operationRepository.ValidateWithDbAsync(new[] { wellOperation }, cancellationToken); - if (validationResult.Any()) - return this.ValidationBadRequest(validationResult); - var result = await operationRepository.InsertRangeAsync(new[] { wellOperation }, cancellationToken); return Ok(result); @@ -290,32 +286,11 @@ namespace AsbCloudWebApi.Controllers wellOperation.IdType = idType; } - - var validationResult = await Validate(wellOperations, deleteBeforeInsert, cancellationToken); - if (validationResult.Any()) - return this.ValidationBadRequest(validationResult); - var result = await operationRepository.InsertRangeAsync(wellOperations, cancellationToken); return Ok(result); } - - /// - /// Валидация данных перед вставкой / обновлением / импортом - /// - /// - /// - /// - /// - private async Task> Validate(IEnumerable wellOperations, bool deleteBeforeInsert, CancellationToken cancellationToken) - { - if (deleteBeforeInsert) - return operationRepository.Validate(wellOperations); - else - return await operationRepository.ValidateWithDbAsync(wellOperations, cancellationToken); - } - /// /// Обновляет выбранную операцию на скважине /// @@ -341,10 +316,6 @@ namespace AsbCloudWebApi.Controllers value.LastUpdateDate = DateTimeOffset.UtcNow; value.IdUser = User.GetUserId(); - var validationResult = await operationRepository.ValidateWithDbAsync(new[] { value }, token); - if (validationResult.Any()) - return this.ValidationBadRequest(validationResult); - var result = await operationRepository.UpdateAsync(value, token) .ConfigureAwait(false); return Ok(result);