using AsbCloudApp.Data.ProcessMaps.Report;
using AsbCloudApp.Requests;
using AsbCloudApp.Services.ProcessMaps.WellDrilling;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudWebApi.Controllers.ProcessMaps;
///
/// РТК отчет по бурению
///
[ApiController]
[Route("api/well/{idWell:int}/[controller]")]
[Authorize]
public class ProcessMapReportDrillingController: ControllerBase
{
private readonly IProcessMapReportDrillingService processMapReportDrillingService;
private readonly IProcessMapReportDrillingExportService processMapReportDrillingExportService;
public ProcessMapReportDrillingController(
IProcessMapReportDrillingExportService processMapReportDrillingExportService,
IProcessMapReportDrillingService processMapReportDrillingService)
{
this.processMapReportDrillingExportService = processMapReportDrillingExportService;
this.processMapReportDrillingService = processMapReportDrillingService;
}
///
/// Получение данных для отчета РТК бурение
///
/// Id
/// параметры запроса
///
///
[HttpGet("report")]
[ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)]
public async Task GetReportAsync(int idWell, [FromQuery] DataSaubStatRequest request, CancellationToken cancellationToken)
{
var report = await processMapReportDrillingService.GetAsync(idWell, request, cancellationToken);
return Ok(report);
}
///
/// Экспорт отчета РТК бурение
///
/// Id скважины
/// Параметры запроса
///
///
[HttpGet("report/export")]
[ProducesResponseType(typeof(PhysicalFileResult), StatusCodes.Status200OK, "application/octet-stream")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task ExportReportAsync(int idWell, [FromQuery] DataSaubStatRequest request, CancellationToken cancellationToken)
{
var report = await processMapReportDrillingExportService.ExportAsync(idWell, request, cancellationToken);
if (report is null)
return NoContent();
return File(report.Value.File, "application/octet-stream", report.Value.Name);
}
}