Метод UpdateWellStateAsync контроллера WellController

This commit is contained in:
Olga Nemt 2023-05-02 16:47:16 +05:00
parent 7aadcbe69b
commit 46799baace

View File

@ -1,8 +1,10 @@
using AsbCloudApp.Data;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Threading;
using System.Threading.Tasks;
@ -112,5 +114,35 @@ namespace AsbCloudWebApi.Controllers
return Ok(result);
}
/// <summary>
/// Обновляет статус скважины
/// </summary>
/// <param name="idWell">ключ скважины</param>
/// <param name="idState">статус: 0 - Неизвестно, 1 - В работе, 2 - Завершена.</param>
/// <param name="token"></param>
/// <returns></returns>
[HttpPut("{idWell}/state")]
[Permission]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> UpdateWellStateAsync(int idWell,
[Range(0, 2, ErrorMessage = "Статус некорректен")] int idState,
CancellationToken token = default)
{
var idCompany = User.GetCompanyId();
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false))
return Forbid();
var dto = wellService.GetOrDefault(idWell)!;
dto.IdState = idState;
var result = await wellService.UpdateAsync(dto, token)
.ConfigureAwait(false);
return Ok(result);
}
}
}