Skip to content

Commit

Permalink
Change streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
FirestarJes committed Sep 30, 2024
1 parent f2ea601 commit b3e6c9a
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ namespace Energinet.DataHub.SettlementReport.Application.Handlers;

public interface ISettlementReportJobsDownloadHandler
{
Task DownloadReportAsync(SettlementReportRequestId requestId, Func<Stream> outputStreamProvider, Guid actorId, bool isMultitenancy);
Task<Stream> DownloadReportAsync(SettlementReportRequestId requestId, Guid actorId, bool isMultitenancy);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ public SettlementReportJobsDownloadHandler(
_repository = repository;
}

public async Task DownloadReportAsync(
public async Task<Stream> DownloadReportAsync(
SettlementReportRequestId requestId,
Func<Stream> outputStreamProvider,
Guid actorId,
bool isMultitenancy)
{
Expand All @@ -48,8 +47,8 @@ public async Task DownloadReportAsync(
if (string.IsNullOrEmpty(report.BlobFileName))
throw new InvalidOperationException("Report does not have a Blob file name.");

await _fileRepository
.DownloadAsync(report.BlobFileName, outputStreamProvider())
return await _fileRepository
.DownloadAsync(report.BlobFileName)
.ConfigureAwait(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ namespace Energinet.DataHub.SettlementReport.Application.SettlementReports_v2;

public interface ISettlementReportJobsFileRepository
{
Task DownloadAsync(string blobFileName, Stream downloadStream);
Task<Stream> DownloadAsync(string blobFileName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public SettlementReportJobsFileBlobStorage(BlobContainerClient blobContainerClie
_blobContainerClient = blobContainerClient;
}

public async Task DownloadAsync(string fileName, Stream downloadStream)
public async Task<Stream> DownloadAsync(string fileName)
{
var blobName = GetBlobName(fileName);
var blobClient = _blobContainerClient.GetBlobClient(blobName);
await blobClient.DownloadToAsync(downloadStream).ConfigureAwait(false);
return await blobClient.OpenReadAsync().ConfigureAwait(false);
}

private static string GetBlobName(string fileName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,15 @@ public async Task<IEnumerable<RequestedSettlementReportDto>> ListSettlementRepor
[Route("download")]
[Authorize]
[Produces("application/octet-stream")]
[ProducesResponseType(typeof(FileResult), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(FileStreamResult), StatusCodes.Status200OK)]
[EnableRevision(activityName: "DownloadSettlementReportAPI", entityType: typeof(RequestedSettlementReportDto))]
public async Task<ActionResult> DownloadFileAsync([FromBody]SettlementReportRequestId requestId)
{
try
{
var stream = new MemoryStream();
await _downloadHandler
var stream = await _downloadHandler
.DownloadReportAsync(
requestId,
() => stream,
_userContext.CurrentUser.Actor.ActorId,
_userContext.CurrentUser.MultiTenancy)
.ConfigureAwait(false);
Expand Down

0 comments on commit b3e6c9a

Please sign in to comment.