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/[controller]")]
[ApiController]
[Authorize]
public class WellFinalDocumentsController : ControllerBase
{
private readonly IWellFinalDocumentsService wellFinalDocumentsService;
public WellFinalDocumentsController(IWellFinalDocumentsService wellFinalDocumentsService)
{
this.wellFinalDocumentsService = wellFinalDocumentsService;
}
///
/// Получение всех записей
///
///
///
///
[HttpGet]
[Permission]
[ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)]
public async Task GetAsync(int idWell, CancellationToken token = default)
{
var data = await this.wellFinalDocumentsService.GetByWellId(idWell, token);
return Ok(data);
}
///
/// Получение списка ответственных
///
///
///
///
[HttpGet]
[Permission]
[Route("publishers")]
[ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)]
public async Task GetPublishersAsync(int idWell, CancellationToken token = default)
{
var data = await this.wellFinalDocumentsService.GetPublishersAsync(idWell, token);
return Ok(data);
}
///
/// Добавление записи
///
///
///
///
[HttpPut]
[Permission]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
public async Task InsertRangeAsync(IEnumerable dtos, CancellationToken token = default)
{
var data = await this.wellFinalDocumentsService.InsertRangeAsync(dtos, token);
return Ok(data);
}
///
/// Удалить запись
///
///
///
///
[HttpDelete]
[Permission]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
public async Task DeleteAsync(int iDdto, CancellationToken token = default)
{
var data = await this.wellFinalDocumentsService.DeleteAsync(iDdto, 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 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 idDto, int idUser,
IFormFile file, CancellationToken token = default)
{
var fileStream = file.OpenReadStream();
var data = await this.wellFinalDocumentsService.SaveCategoryFile(idDto, idUser, fileStream, file.FileName, token);
return Ok(data);
}
}
}