Добавлен метод API экспорта отчёта по скважине

This commit is contained in:
Степанов Дмитрий 2024-09-02 10:16:04 +05:00
parent 307c29fcfd
commit e2f053af6c

View File

@ -1,13 +1,12 @@
using AsbCloudApp.Data;
using AsbCloudApp.Exceptions;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Services.WellReport;
using Microsoft.AspNetCore.Http;
namespace AsbCloudWebApi.Controllers;
@ -21,11 +20,13 @@ namespace AsbCloudWebApi.Controllers;
public class WellController : ControllerBase
{
private readonly IWellService wellService;
private readonly IWellReportExportService wellReportExportService;
public WellController(IWellService wellService)
{
this.wellService = wellService;
}
public WellController(IWellService wellService, IWellReportExportService wellReportExportService)
{
this.wellService = wellService;
this.wellReportExportService = wellReportExportService;
}
/// <summary>
/// Возвращает список доступных скважин
@ -151,16 +152,24 @@ public class WellController : ControllerBase
}
//TODO: навзание пока такое. У нас в API уже есть метод с такой сигнатурой.
/// <summary>
/// Получить отчёт по скважине
/// </summary>
/// <param name="idWell"></param>
/// <param name="token"></param>
/// <returns></returns>
[HttpGet("{idWell}/report")]
[ProducesResponseType(typeof(PhysicalFileResult), StatusCodes.Status200OK)]
public Task<IActionResult> GetReportAsync(int idWell, CancellationToken token)
[HttpGet("{idWell}/report/export")]
[ProducesResponseType(typeof(PhysicalFileResult), StatusCodes.Status200OK, "application/octet-stream")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> ExportAsync(int idWell, CancellationToken token)
{
var report = await wellReportExportService.ExportAsync(idWell, token);
if (report is null)
return NoContent();
return File(report.Value.File, "application/octet-stream", report.Value.Name);
}
}