forked from ddrilling/AsbCloudServer
eugeniy_ivanov
1e694216a9
в контроллере доделан экшн получения списка подсистем и добавлена проверка доступа пользователя к скважине
105 lines
4.3 KiB
C#
105 lines
4.3 KiB
C#
using AsbCloudApp.Data.Subsystems;
|
|
using AsbCloudApp.Requests;
|
|
using AsbCloudApp.Services;
|
|
using AsbCloudApp.Services.Subsystems;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AsbCloudWebApi.Controllers.Subsystems
|
|
{
|
|
/// <summary>
|
|
/// Наработка подсистем
|
|
/// </summary>
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
[Authorize]
|
|
public class SubsystemOperationTimeController : ControllerBase
|
|
{
|
|
private readonly ISubsystemOperationTimeService subsystemOperationTimeService;
|
|
private readonly ICrudService<SubsystemDto> subsystemService;
|
|
private readonly IWellService wellService;
|
|
public SubsystemOperationTimeController(ISubsystemOperationTimeService subsystemOperationTimeService, ICrudService<SubsystemDto> subsystemService, IWellService wellService)
|
|
{
|
|
this.subsystemOperationTimeService = subsystemOperationTimeService;
|
|
this.subsystemService = subsystemService;
|
|
this.wellService = wellService;
|
|
}
|
|
/// <summary>
|
|
/// получить статистику
|
|
/// </summary>
|
|
[HttpGet("stat")]
|
|
[ProducesResponseType(typeof(IEnumerable<SubsystemStatDto>), (int)System.Net.HttpStatusCode.OK)]
|
|
public async Task<IActionResult> GetStatAsync([FromQuery] SubsystemOperationTimeRequest request, CancellationToken token = default)
|
|
{
|
|
if (!await UserHasAccesToWellAsync(request.IdWell, token))
|
|
return Forbid();
|
|
var subsystemResult = await subsystemOperationTimeService.GetStatAsync(request, token);
|
|
return Ok(subsystemResult);
|
|
}
|
|
|
|
/// <summary>
|
|
/// получить список подсистем общий.
|
|
/// </summary>
|
|
[HttpGet("subsystem")]
|
|
[ProducesResponseType(typeof(IEnumerable<SubsystemDto>), (int)System.Net.HttpStatusCode.OK)]
|
|
public async Task<IActionResult> GetSubsystemAsync([FromQuery] int? idWell, CancellationToken token = default)
|
|
{
|
|
if (idWell.HasValue)
|
|
if (!await UserHasAccesToWellAsync(idWell.Value, token))
|
|
return Forbid();
|
|
|
|
var result = await subsystemOperationTimeService.GetSubsystemAsync(idWell, token);
|
|
return Ok(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// получить список наработок подсистем
|
|
/// </summary>
|
|
[HttpGet("operationTime")]
|
|
[ProducesResponseType(typeof(IEnumerable<SubsystemOperationTimeDto>), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
public async Task<IActionResult> GetOperationTimeAsync(
|
|
[FromQuery] SubsystemOperationTimeRequest request,
|
|
CancellationToken token = default)
|
|
{
|
|
if (!await UserHasAccesToWellAsync(request.IdWell, token))
|
|
return Forbid();
|
|
var result = await subsystemOperationTimeService.GetOperationTimeAsync(request, token);
|
|
return Ok(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Удалить наработки.
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <param name="token"></param>
|
|
/// <returns></returns>
|
|
[HttpDelete]
|
|
[Permission]
|
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
|
public async Task<IActionResult> DeleteAsync(
|
|
[FromQuery] SubsystemOperationTimeRequest request,
|
|
CancellationToken token)
|
|
{
|
|
if (!await UserHasAccesToWellAsync(request.IdWell, token))
|
|
return Forbid();
|
|
var result = await subsystemOperationTimeService.DeleteAsync(request, token);
|
|
return Ok(result);
|
|
}
|
|
|
|
protected async Task<bool> UserHasAccesToWellAsync(int idWell, CancellationToken token)
|
|
{
|
|
var idCompany = User.GetCompanyId();
|
|
if (idCompany is not null &&
|
|
await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token)
|
|
.ConfigureAwait(false))
|
|
return true;
|
|
return false;
|
|
}
|
|
}
|
|
}
|