From 04c984e55837f4d2f450a25f03c19fa939db688c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=82=D0=B5=D0=BF=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94?= =?UTF-8?q?=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Tue, 30 Jul 2024 15:07:15 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BF?= =?UTF-8?q?=D0=BE=D1=81=D0=BB=D0=B5=20=D1=80=D0=B5=D0=B2=D1=8C=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repositories/IWellOperationRepository.cs | 2 +- .../Repository/WellOperationRepository.cs | 46 +++++++++---------- .../Controllers/WellOperationController.cs | 10 ++-- 3 files changed, 28 insertions(+), 30 deletions(-) diff --git a/AsbCloudApp/Repositories/IWellOperationRepository.cs b/AsbCloudApp/Repositories/IWellOperationRepository.cs index 8a5bf81c..612d58d9 100644 --- a/AsbCloudApp/Repositories/IWellOperationRepository.cs +++ b/AsbCloudApp/Repositories/IWellOperationRepository.cs @@ -48,7 +48,7 @@ namespace AsbCloudApp.Repositories int id, int operationType, int? take, - IEnumerable sortFields, + IEnumerable? sortFields, CancellationToken token); /// diff --git a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs index 0967bafb..843956cb 100644 --- a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs +++ b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs @@ -75,44 +75,42 @@ public class WellOperationRepository : CrudRepositoryBase sortFields, + IEnumerable? sortFields, CancellationToken token) { - var query = GetQuery() - .Where(o => o.IdType == operationType && - o.IdWell == idWell); - - if (!await query.AnyAsync(x => x.Id == id, token)) - return null; + var request = new WellOperationRequest(new[] { idWell }) + { + OperationType = operationType, + SortFields = sortFields, + }; - query = sortFields?.Any() is true ? query.SortBy(sortFields) : query.OrderBy(e => e.DateStart); + var (wellOperations, count) = await GetWithDaysAndNpvAsync(request, token); var skip = 0; take ??= 32; - var count = await query.CountAsync(token); - while (skip < count) { - var isExists = await query.Skip(skip) - .Take(take.Value) - .AnyAsync(x => x.Id == id, token); + var page = wellOperations.Skip(skip) + .Take(take.Value); - if (isExists) - break; + if (page.Any(x => x.Id == id)) + { + var paginationContainer = new PaginationContainer + { + Skip = skip, + Take = take.Value, + Items = page, + Count = count + }; + + return paginationContainer; + } skip += take.Value; } - var request = new WellOperationRequest(new[] { idWell }) - { - OperationType = operationType, - Skip = skip, - Take = take, - SortFields = sortFields - }; - - return await GetPageAsync(request, token); + return null; } public async Task> GetGroupOperationsStatAsync(WellOperationRequest request, CancellationToken token) diff --git a/AsbCloudWebApi/Controllers/WellOperationController.cs b/AsbCloudWebApi/Controllers/WellOperationController.cs index 2019615f..90b7404f 100644 --- a/AsbCloudWebApi/Controllers/WellOperationController.cs +++ b/AsbCloudWebApi/Controllers/WellOperationController.cs @@ -213,7 +213,7 @@ public class WellOperationController : ControllerBase /// [HttpGet("getPageWithOperation")] [Permission] - [ProducesResponseType(typeof(int), StatusCodes.Status200OK)] + [ProducesResponseType(typeof(PaginationContainer), StatusCodes.Status200OK)] public async Task GetPageWithOperationAsync([FromRoute] int idWell, int id, int operationType, @@ -224,12 +224,12 @@ public class WellOperationController : ControllerBase if (!await CanUserAccessToWellAsync(idWell, token)) return Forbid(); - var indexPage = await wellOperationRepository.GetPageAsync(idWell, id, operationType, take, sortFields, token); + var paginationContainer = await wellOperationRepository.GetPageAsync(idWell, id, operationType, take, sortFields, token); - if (indexPage == null) + if (paginationContainer == null) return NoContent(); - - return Ok(indexPage); + + return Ok(paginationContainer); } ///