using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Strata.Stratasphere.Biz.Mappings.Exports; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; namespace Strata.Stratasphere.Api.Controllers { [ApiController] [ApiVersion("1.0")] [Route("api/v{api-version:apiVersion}/[controller]")] public class ExportController : ControllerBase { private readonly IExportJobService _exportJobService; public ExportController(IExportJobService exportJobService) { _exportJobService = exportJobService; } [HttpGet("[action]")] [ProducesResponseType(StatusCodes.Status202Accepted)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] [ProducesDefaultResponseType] public async Task Download([FromQuery] string filename, CancellationToken cancellationToken) { var memoryStream = await _exportJobService.DownloadFile(filename, cancellationToken); return new FileContentResult(memoryStream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") { FileDownloadName = filename }; } [HttpGet("[action]")] public async Task> GetExports(CancellationToken cancellationToken) { return await _exportJobService.GetExports(cancellationToken); } } }