From 37e03b3f0dfbe040cfbae219ad227af8a8886c2c Mon Sep 17 00:00:00 2001 From: KharchenkoVladimir Date: Mon, 18 Oct 2021 16:30:14 +0500 Subject: [PATCH] CS2-98: Added WellUpdateParamsDto in WellController.UpdateWellAsync(). --- AsbCloudApp/Data/WellUpdateDto.cs | 11 ++++++ AsbCloudApp/Services/IWellService.cs | 4 +-- .../Services/WellService.cs | 34 ++++++++----------- AsbCloudWebApi/Controllers/WellController.cs | 17 ++++------ 4 files changed, 33 insertions(+), 33 deletions(-) create mode 100644 AsbCloudApp/Data/WellUpdateDto.cs diff --git a/AsbCloudApp/Data/WellUpdateDto.cs b/AsbCloudApp/Data/WellUpdateDto.cs new file mode 100644 index 00000000..998dd40c --- /dev/null +++ b/AsbCloudApp/Data/WellUpdateDto.cs @@ -0,0 +1,11 @@ +namespace AsbCloudApp.Data +{ + public class WellUpdateParamsDto + { + public string Caption { get; set; } + public double? Latitude { get; set; } + public double? Longitude { get; set; } + public int IdWellType { get; set; } + public int State { get; set; } + } +} \ No newline at end of file diff --git a/AsbCloudApp/Services/IWellService.cs b/AsbCloudApp/Services/IWellService.cs index c76ff7cd..627bb572 100644 --- a/AsbCloudApp/Services/IWellService.cs +++ b/AsbCloudApp/Services/IWellService.cs @@ -8,9 +8,7 @@ namespace AsbCloudApp.Services public interface IWellService { Task> GetWellsByCompanyAsync(int idCompany, CancellationToken token); - Task UpdateWellAsync(int idWell, string caption = default, - double latitude = default, double longitude = default, int idWellType = default, - int state = default, CancellationToken token = default); + Task UpdateWellAsync(int idWell, WellUpdateParamsDto dto, CancellationToken token = default); Task> GetTransmittingWellsAsync(int idCompany, CancellationToken token); Task IsCompanyInvolvedInWellAsync(int idCompany, int idWell, CancellationToken token); Task GetWellCaptionByIdAsync(int idWell, CancellationToken token); diff --git a/AsbCloudInfrastructure/Services/WellService.cs b/AsbCloudInfrastructure/Services/WellService.cs index 41c90ae3..e09263c1 100644 --- a/AsbCloudInfrastructure/Services/WellService.cs +++ b/AsbCloudInfrastructure/Services/WellService.cs @@ -43,33 +43,27 @@ namespace AsbCloudInfrastructure.Services }); } - public async Task UpdateWellAsync(int idWell, string caption = default, - double latitude = default, double longitude = default, int idWellType = default, - int state = default, CancellationToken token = default) + public async Task UpdateWellAsync(int idWell, WellUpdateParamsDto dto, + CancellationToken token = default) { + if (dto.IdWellType is < 1 or > 2) + throw new ArgumentException("Тип секции указан неправильно."); + + if (dto.State is < 0 or > 2) + throw new ArgumentException("Текущее состояние работы скважины" + + "указано неправильно."); var well = await db.Wells .FirstOrDefaultAsync(w => w.Id == idWell, token) .ConfigureAwait(false); if (well is null) - return 0; + return null; - if (caption != default) - well.Caption = caption; - - if (latitude != default) - well.Latitude = latitude; - - if (longitude != default) - well.Longitude = longitude; - - if (idWellType != default) - well.IdWellType = idWellType; - - if (state < 3) - well.State = state; - else - throw new ArgumentException("Недопустимое значение состояния работы скважины"); + well.Caption = dto.Caption; + well.Latitude = dto.Latitude; + well.Longitude = dto.Longitude; + well.IdWellType = dto.IdWellType; + well.State = dto.State; db.Wells.Update(well); diff --git a/AsbCloudWebApi/Controllers/WellController.cs b/AsbCloudWebApi/Controllers/WellController.cs index e896fa32..b01ca18e 100644 --- a/AsbCloudWebApi/Controllers/WellController.cs +++ b/AsbCloudWebApi/Controllers/WellController.cs @@ -74,18 +74,15 @@ namespace AsbCloudWebApi.Controllers /// Редактирует указанные поля скважины /// /// Id скважины - /// Название скважины - /// Широта координат скважины - /// Долгота координат скважины - /// Id типа скважины - /// Id текущего состояния скважины + /// Объект параметров скважины. + /// IdWellType: 1 - Наклонно-направленная, 2 - Горизонтальная. + /// State: 0 - Неизвестно, 1 - В работе, 2 - Завершена. /// Токен отмены задачи /// [HttpPut] [ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)] - public async Task UpdateWellAsync(int idWell, string caption = default, - double latitude = default, double longitude = default, int idWellType = default, - int state = default, CancellationToken token = default) + public async Task UpdateWellAsync(int idWell, WellUpdateParamsDto dto, + CancellationToken token = default) { var idCompany = User.GetCompanyId(); @@ -93,8 +90,8 @@ namespace AsbCloudWebApi.Controllers idWell, token).ConfigureAwait(false)) return Forbid(); - var result = await wellService.UpdateWellAsync(idWell, caption, latitude, longitude, - idWellType, state, token).ConfigureAwait(false); + var result = await wellService.UpdateWellAsync(idWell, dto, token) + .ConfigureAwait(false); return Ok(result);