DD.WellWorkover.Cloud/AsbCloudWebApi/Controllers/DrillingProgramController.cs

56 lines
2.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudWebApi.Controllers
{
[Route("api/well/{idWell}/drillingProgram")]
[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;
}
/// <summary>
/// Создает программу бурения
/// </summary>
/// <param name="idWell"> id скважины </param>
/// <param name="token"> Токен отмены задачи </param>
/// <returns> Возвращает ссылку на файл в облаке </returns>
[HttpGet]
[ProducesResponseType(typeof(string), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetAsync(int idWell, CancellationToken token = default)
{
var fileInfo = await drillingProgramService.GetAsync(idWell, token)
.ConfigureAwait(false);
if (fileInfo is null)
return NoContent();
// Чтоб не смешивать этот временный функционал с основным публикация на гугл диск вся вынесена сюда
// и выполняется уже после всех необходимых действий по созданию файла программы бурения.
var fileWebLink = await fileService.GetProgramWebUrlAsync(fileInfo.Id);
if (!string.IsNullOrEmpty(fileWebLink))
return Ok(fileWebLink);
var relativePath = fileService.GetUrl(fileInfo);
fileWebLink = await fileService.PublishFileToCloudAsync(relativePath,
fileInfo.Name, token);
await fileService.SaveWeblinkToFileInfo(fileInfo.Id, fileWebLink, token);
return Ok(fileWebLink);
//return PhysicalFile(Path.GetFullPath(relativePath), "application/octet-stream", fileInfo.Name);
}
}
}