Update SurveyLib and add Excel export functionality

This commit is contained in:
Вячеслав 2025-06-09 02:11:34 +05:00
parent 690eaaa32f
commit 837f90db52
5 changed files with 37 additions and 1 deletions

View file

@ -0,0 +1,26 @@
using Microsoft.AspNetCore.Mvc;
using SurveyLib.Tools.Tools;
namespace SurveyBackend.Controllers;
[ApiController]
[Route("api/export")]
public class ExportController
{
private readonly TableExporter _tableExporter;
public ExportController(TableExporter tableExporter)
{
_tableExporter = tableExporter;
}
[HttpGet("excel/{surveyId:int}")]
public async Task<IActionResult> ExportSurveyById(int surveyId)
{
var fileBytes = await _tableExporter.ExportDataBySurveyIdAsync(surveyId);
return new FileContentResult(fileBytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
{
FileDownloadName = $"survey_{surveyId}_{DateTime.UtcNow:yyyyMMdd_HHmmss}.xlsx"
};
}
}

View file

@ -12,6 +12,7 @@ using SurveyBackend.Middlewares;
using SurveyBackend.Services;
using SurveyLib.Infrastructure.EFCore;
using SurveyLib.Infrastructure.EFCore.Data;
using SurveyLib.Tools.Tools;
namespace SurveyBackend;
@ -38,6 +39,8 @@ public class Program
builder.Services.AddSurveyLibInfrastructure();
builder.Services.AddSurveyBackendServices();
builder.Services.AddScoped<TableExporter>();
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{

View file

@ -33,6 +33,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\SurveyLib\SurveyLib.Tools\SurveyLib.Tools.csproj" />
<ProjectReference Include="..\SurveyBackend.Core\SurveyBackend.Core.csproj"/>
<ProjectReference Include="..\SurveyBackend.Infrastructure\SurveyBackend.Infrastructure.csproj"/>
<ProjectReference Include="..\SurveyBackend.Services\SurveyBackend.Services.csproj"/>

View file

@ -12,6 +12,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SurveyLib.Core", "..\Survey
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SurveyBackend.Services", "SurveyBackend.Services\SurveyBackend.Services.csproj", "{3CDA6495-4FB2-4F07-8B2F-15BFD2A35181}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SurveyLib.Tools", "..\SurveyLib\SurveyLib.Tools\SurveyLib.Tools.csproj", "{DA10F9E0-2682-438E-BC2B-C22B6BBD13CB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -42,5 +44,9 @@ Global
{3CDA6495-4FB2-4F07-8B2F-15BFD2A35181}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3CDA6495-4FB2-4F07-8B2F-15BFD2A35181}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3CDA6495-4FB2-4F07-8B2F-15BFD2A35181}.Release|Any CPU.Build.0 = Release|Any CPU
{DA10F9E0-2682-438E-BC2B-C22B6BBD13CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DA10F9E0-2682-438E-BC2B-C22B6BBD13CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DA10F9E0-2682-438E-BC2B-C22B6BBD13CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DA10F9E0-2682-438E-BC2B-C22B6BBD13CB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal