Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 0 additions & 108 deletions ScriptBeeWebApp/EndpointDefinitions/OutputEndpointDefinition.cs

This file was deleted.

71 changes: 0 additions & 71 deletions ScriptBeeWebApp/EndpointDefinitions/RunScriptEndpointDefinition.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
using System.Net.Mime;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
using ScriptBee.Common.Web;
using ScriptBee.Common.Web.Extensions;
using ScriptBee.Domain.Model.Analysis;
using ScriptBee.Domain.Model.Project;
using ScriptBee.Service.Project.Analysis;
using ScriptBee.UseCases.Project.Analysis;

namespace ScriptBee.Web.EndpointDefinitions.Analysis;

using DownloadResult = Results<FileStreamHttpResult, NotFound<ProblemDetails>>;

public class DownloadAnalysisFileResultsEndpoint : IEndpointDefinition
{
public void DefineServices(IServiceCollection services)
{
services.AddSingleton<
IDownloadAnalysisFileResultsUseCase,
DownloadAnalysisFileResultsService
>();
}

public void DefineEndpoints(IEndpointRouteBuilder app)
{
app.MapGet(
"/api/projects/{projectId}/analyses/{analysisId}/results/files/{fileId}",
DownloadIndividualFile
);

app.MapGet(
"/api/projects/{projectId}/analyses/{analysisId}/results/files/download",
DownloadAllFiles
);
}

private static async Task<DownloadResult> DownloadIndividualFile(
HttpContext context,
[FromRoute] string projectId,
[FromRoute] string analysisId,
[FromRoute] string fileId,
IDownloadAnalysisFileResultsUseCase useCase,
CancellationToken cancellationToken = default
)
{
var result = await useCase.GetFileResultStream(
ProjectId.FromValue(projectId),
new AnalysisId(analysisId),
new ResultId(fileId),
cancellationToken
);

return result.Match<DownloadResult>(
namedStream =>
TypedResults.File(
namedStream.Stream,
MediaTypeNames.Application.Octet,
namedStream.Name
),
error =>
TypedResults.NotFound(
context.ToProblemDetails(
"Analysis Not Found",
$"An analysis with the ID '{error.Id.Value}' does not exists."
)
),
error =>
TypedResults.NotFound(
context.ToProblemDetails(
"Result Not Found",
$"An analysis result with the ID '{error.Id.Value}' does not exists."
)
)
);
}

private static async Task<DownloadResult> DownloadAllFiles(
HttpContext context,
[FromRoute] string projectId,
[FromRoute] string analysisId,
IDownloadAnalysisFileResultsUseCase useCase,
CancellationToken cancellationToken = default
)
{
var result = await useCase.GetAllFilesZipStream(
ProjectId.FromValue(projectId),
new AnalysisId(analysisId),
cancellationToken
);

return result.Match<DownloadResult>(
namedStream =>
TypedResults.File(
namedStream.Stream,
MediaTypeNames.Application.Octet,
namedStream.Name
),
error =>
TypedResults.NotFound(
context.ToProblemDetails(
"Analysis Not Found",
$"An analysis with the ID '{error.Id.Value}' does not exists."
)
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public void DefineEndpoints(IEndpointRouteBuilder app)
"/api/projects/{projectId}/analyses/{analysisId}/results/files",
GetFilesAnalysisResult
);
// TODO FIXIT: add endpoints for download result, download all files, download all results(console,output-errors,files)
}

private static async Task<
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace ScriptBee.Domain.Model.Analysis;

public record AnalysisResultDoesNotExistsError(ResultId Id);
Loading