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; namespace AsbCloudWebApi.Controllers { /// /// Дело скважины /// [Route("api/wellFinalDocuments")] [ApiController] [Authorize] public class WellFinalDocumentsController : ControllerBase { private readonly IWellFinalDocumentsService wellFinalDocumentsService; public WellFinalDocumentsController(IWellFinalDocumentsService wellFinalDocumentsService) { this.wellFinalDocumentsService = wellFinalDocumentsService; } /// /// Получение всех записей /// /// /// /// [HttpGet] [Permission] public async Task GetAsync(int idWell, CancellationToken token = default) { var data = await this.wellFinalDocumentsService.GetByWellId(idWell, token); return Ok(data); } /// /// Получение списка ответственных /// /// /// /// [HttpGet] [Permission] [Route("getResponsibles")] public async Task GetResponsiblesAsync(int idWell, CancellationToken token = default) { var data = await this.wellFinalDocumentsService.GetListResponsiblesAsync(idWell, token); return Ok(data); } /// /// Добавление записи /// /// /// /// [HttpPut] [Permission] public async Task InsertRangeAsync(List dtos, CancellationToken token = default) { var data = await this.wellFinalDocumentsService.InsertRangeAsync(dtos, token); return Ok(data); } /// /// Удалить запись /// /// /// /// [HttpDelete] [Permission] public async Task DeleteAsync(int iDdto, CancellationToken token = default) { var data = await this.wellFinalDocumentsService.DeleteAsync(iDdto, token); return Ok(data); } /// /// Получение истории файлов /// /// /// /// /// [HttpGet] [Permission] [Route("getHistoryFileByIdCategory")] public async Task GetHistoryFileByIdCategory(int idWell, int idCategory, CancellationToken token = default) { var data = await this.wellFinalDocumentsService.GetHistoryFileByIdCategory(idWell, idCategory, token); return Ok(data); } /// /// Сохранение файла /// /// /// /// /// [HttpPost] [Permission] [ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)] public async Task SaveFilesAsync(int idDto, IFormFile file, CancellationToken token = default) { var fileStream = file.OpenReadStream(); var data = await this.wellFinalDocumentsService.SaveCategoryFile(idDto, fileStream, file.FileName, token); return Ok(data); } } }