2021-08-29 17:25:16 +05:00
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Controllers
|
|
|
|
|
{
|
2021-08-29 17:29:24 +05:00
|
|
|
|
[Route("api/well/{idWell}/drillingProgram")]
|
2021-08-29 17:25:16 +05:00
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
|
|
|
|
public class DrillingProgramController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly IDrillingProgramService drillingProgramService;
|
|
|
|
|
private readonly IFileService fileService;
|
|
|
|
|
|
|
|
|
|
public DrillingProgramController(IDrillingProgramService drillingProgramService, IFileService fileService)
|
|
|
|
|
{
|
|
|
|
|
this.drillingProgramService = drillingProgramService;
|
|
|
|
|
this.fileService = fileService;
|
|
|
|
|
}
|
2021-10-27 17:23:43 +05:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создает программу бурения
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"> id скважины </param>
|
|
|
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
|
|
|
/// <returns> Файл программы бурения </returns>
|
2021-08-29 17:25:16 +05:00
|
|
|
|
[HttpGet]
|
|
|
|
|
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetAsync(int idWell, CancellationToken token = default)
|
|
|
|
|
{
|
|
|
|
|
var fileInfo = await drillingProgramService.GetAsync(idWell, token)
|
|
|
|
|
.ConfigureAwait(false);
|
2021-09-01 15:55:10 +05:00
|
|
|
|
if (fileInfo is null)
|
|
|
|
|
return NoContent();
|
2021-09-23 10:53:48 +05:00
|
|
|
|
var relativePath = fileService.GetUrl(fileInfo);
|
2021-10-27 17:00:27 +05:00
|
|
|
|
|
2021-08-29 17:25:16 +05:00
|
|
|
|
return PhysicalFile(Path.GetFullPath(relativePath), "application/octet-stream", fileInfo.Name);
|
|
|
|
|
}
|
2021-10-27 17:00:27 +05:00
|
|
|
|
|
2021-10-27 17:23:43 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Публикует файл программы бурения в облако (только если программа уже создана)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"> id скважины </param>
|
|
|
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
|
|
|
/// <returns> Возвращает ссылку на файл программы бурения в облаке (только если программа уже создана) </returns>
|
2021-10-27 17:00:27 +05:00
|
|
|
|
[HttpGet("webLink")]
|
|
|
|
|
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetWebLinkAsync(int idWell, CancellationToken token = default)
|
|
|
|
|
{
|
|
|
|
|
var fileInfo = await drillingProgramService.GetAsync(idWell, token)
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
if (fileInfo is null)
|
|
|
|
|
return NoContent();
|
|
|
|
|
var relativePath = fileService.GetUrl(fileInfo);
|
|
|
|
|
|
|
|
|
|
var fileWebLink = fileService.CreateGoogleDriveWebLink(relativePath, fileInfo.Name);
|
|
|
|
|
await fileService.SaveWeblinkToFileInfo(fileInfo.Id, fileWebLink, token);
|
|
|
|
|
|
|
|
|
|
return Ok(fileWebLink);
|
|
|
|
|
}
|
2021-08-29 17:25:16 +05:00
|
|
|
|
}
|
|
|
|
|
}
|