2024-07-04 11:02:45 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
2021-08-27 17:55:22 +05:00
|
|
|
|
using AsbCloudApp.Services;
|
2021-08-02 11:39:39 +05:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2021-08-09 15:41:42 +05:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2021-08-11 16:54:42 +05:00
|
|
|
|
using System.Threading;
|
2021-08-11 12:11:21 +05:00
|
|
|
|
using System.Threading.Tasks;
|
2021-08-02 11:39:39 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
namespace AsbCloudWebApi.Controllers;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Измерения
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
|
|
|
|
[Route("api/well/{idWell}/measure")]
|
|
|
|
|
public class MeasureController : ControllerBase
|
2021-08-02 11:39:39 +05:00
|
|
|
|
{
|
2024-08-19 10:01:07 +05:00
|
|
|
|
private readonly IMeasureService measureService;
|
|
|
|
|
private readonly IWellService wellService;
|
|
|
|
|
|
|
|
|
|
public MeasureController(IMeasureService measureService, IWellService wellService)
|
|
|
|
|
{
|
|
|
|
|
this.measureService = measureService;
|
|
|
|
|
this.wellService = wellService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet("categories")]
|
|
|
|
|
[Permission]
|
|
|
|
|
public async Task<IActionResult> GetCategoriesAsync([FromRoute] int idWell, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
var result = await measureService.GetCategoriesAsync(token).ConfigureAwait(false);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet("last/{idCategory}")]
|
|
|
|
|
[Permission]
|
|
|
|
|
public async Task<IActionResult> GetLastAsync([FromRoute] int idWell, [FromRoute] int idCategory, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
var result = await measureService.GetLastOrDefaultAsync(idWell, idCategory, token).ConfigureAwait(false);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-16 17:37:10 +05:00
|
|
|
|
/// <summary>
|
2024-08-19 10:01:07 +05:00
|
|
|
|
/// История замеров по скважине
|
2022-06-16 17:37:10 +05:00
|
|
|
|
/// </summary>
|
2024-08-19 10:01:07 +05:00
|
|
|
|
/// <param name="idWell"></param>
|
|
|
|
|
/// <param name="idCategory">Категория скважины. Не обязательный параметр.</param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("history")]
|
|
|
|
|
[Permission]
|
|
|
|
|
public async Task<IActionResult> GetHisoryAsync([FromRoute] int idWell, CancellationToken token,
|
|
|
|
|
int? idCategory = null)
|
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
var result = await measureService.GetHisoryAsync(idWell, idCategory, token).ConfigureAwait(false);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[Permission]
|
|
|
|
|
public async Task<IActionResult> InsertAsync([FromRoute] int idWell, MeasureDto data, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
var result = await measureService.InsertAsync(idWell, data, token).ConfigureAwait(false);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPut]
|
|
|
|
|
[Permission]
|
|
|
|
|
public async Task<IActionResult> UpdateAsync([FromRoute] int idWell, MeasureDto data, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
var result = await measureService.UpdateAsync(idWell, data, token).ConfigureAwait(false);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpDelete("history/{idData}")]
|
|
|
|
|
[Permission]
|
|
|
|
|
public async Task<IActionResult> MarkAsDeleteAsync([FromRoute] int idWell, [FromRoute] int idData, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
var result = await measureService.MarkAsDeleteAsync(idWell, idData, token).ConfigureAwait(false);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken token)
|
2021-08-02 11:39:39 +05:00
|
|
|
|
{
|
2024-08-19 10:01:07 +05:00
|
|
|
|
int? idCompany = User.GetCompanyId();
|
|
|
|
|
return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false);
|
2021-08-02 11:39:39 +05:00
|
|
|
|
}
|
|
|
|
|
}
|