using AsbCloudApp.Data; using AsbCloudApp.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System.Threading.Tasks; using System.Threading; using System.Collections.Generic; using Microsoft.AspNetCore.Http; using AsbCloudInfrastructure.Services; namespace AsbCloudWebApi.Controllers { #nullable enable /// /// Дело скважины /// [Route("api/[controller]")] [ApiController] [Authorize] public class WellFinalDocumentsController : ControllerBase { private readonly IWellFinalDocumentsService wellFinalDocumentsService; private readonly IWellService wellService; public WellFinalDocumentsController(IWellFinalDocumentsService wellFinalDocumentsService, IWellService wellService) { this.wellFinalDocumentsService = wellFinalDocumentsService; this.wellService = wellService; } /// /// Получение всех записей /// /// /// /// [HttpGet] [Permission] [ProducesResponseType(typeof(WellCaseDto), (int)System.Net.HttpStatusCode.OK)] public async Task GetAsync(int idWell, CancellationToken token = default) { var idCompany = User.GetCompanyId(); if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync(idCompany ?? default, idWell, token).ConfigureAwait(false)) return Forbid(); var idUser = User?.GetUserId(); var data = await this.wellFinalDocumentsService.GetByWellId(idWell, idUser ?? default, token); return Ok(data); } /// /// Получение списка ответственных /// /// /// /// [HttpGet] [Permission] [Route("publishers")] [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] public async Task GetAvailableUsersAsync(int idWell, CancellationToken token = default) { var idCompany = User.GetCompanyId(); if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync(idCompany ?? default, idWell, token).ConfigureAwait(false)) return Forbid(); var data = await this.wellFinalDocumentsService.GetAvailableUsersAsync(idWell, token); return Ok(data); } /// /// Добавление записи /// /// /// /// /// [HttpPut] [Permission] [ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)] public async Task UpdateRangeAsync(int idWell, IEnumerable dtos, CancellationToken token = default) { var data = await this.wellFinalDocumentsService.UpdateRangeAsync(idWell, dtos, token); return Ok(data); } /// /// Получение истории файлов /// /// /// /// /// [HttpGet] [Permission] [Route("filesHistoryByIdCategory")] [ProducesResponseType(typeof(WellFinalDocumentsHistoryDto), (int)System.Net.HttpStatusCode.OK)] public async Task GetFilesHistoryByIdCategory(int idWell, int idCategory, CancellationToken token = default) { var idCompany = User.GetCompanyId(); if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync(idCompany ?? default, idWell, token).ConfigureAwait(false)) return Forbid(); var data = await this.wellFinalDocumentsService.GetFilesHistoryByIdCategory(idWell, idCategory, token); return Ok(data); } /// /// Сохранение файла /// /// /// /// /// /// [HttpPost] [Permission] [ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)] public async Task SaveCategoryFile(int idWell, int idCategory, IFormFile file, CancellationToken token = default) { var idUser = User.GetUserId() ?? -1; var fileStream = file.OpenReadStream(); var data = await this.wellFinalDocumentsService.SaveCategoryFile(idWell, idCategory, idUser, fileStream, file.FileName, token); return Ok(data); } } #nullable disable }