diff --git a/AsbCloudWebApi/Controllers/WellOperationController.cs b/AsbCloudWebApi/Controllers/WellOperationController.cs index 245b1f17..5c6383a2 100644 --- a/AsbCloudWebApi/Controllers/WellOperationController.cs +++ b/AsbCloudWebApi/Controllers/WellOperationController.cs @@ -16,6 +16,7 @@ using AsbCloudApp.Requests.ExportOptions; using AsbCloudApp.Requests.ParserOptions; using AsbCloudDb.Model; using AsbCloudInfrastructure.Services.WellOperations.Factories; +using System.Linq; namespace AsbCloudWebApi.Controllers; @@ -250,6 +251,35 @@ public class WellOperationController : ControllerBase return Ok(result); } + /// + /// Удаляет выбранные операции по скважине + /// + /// id скважины + /// ids выбранных операций + /// Токен отмены задачи + /// Количество удаленных из БД строк + [HttpDelete] + [ProducesResponseType(typeof(int), StatusCodes.Status200OK)] + [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] + public async Task DeleteRangeAsync([FromRoute] int idWell, IEnumerable ids, CancellationToken token) + { + if (!await CanUserAccessToWellAsync(idWell, token)) + return Forbid(); + + if (!await CanUserEditWellOperationsAsync(idWell, token)) + return Forbid(); + + if (!ids.Any()) + return this.ValidationBadRequest(nameof(ids), "Пустой список операций"); + + var result = await wellOperationRepository.DeleteRangeAsync(ids, token); + + if(result == ICrudRepository.ErrorIdNotFound) + return this.ValidationBadRequest(nameof(ids), "Минимум одна из операций не найдена в базе"); + + return Ok(result); + } + /// /// Формирование excel файла с операциями на скважине ///