diff --git a/SurveyBackend/SurveyBackend.API/Controllers/ExportController.cs b/SurveyBackend/SurveyBackend.API/Controllers/ExportController.cs new file mode 100644 index 0000000..23ef2e0 --- /dev/null +++ b/SurveyBackend/SurveyBackend.API/Controllers/ExportController.cs @@ -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 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" + }; + } +} \ No newline at end of file diff --git a/SurveyBackend/SurveyBackend.API/Program.cs b/SurveyBackend/SurveyBackend.API/Program.cs index 3c66899..4529b73 100644 --- a/SurveyBackend/SurveyBackend.API/Program.cs +++ b/SurveyBackend/SurveyBackend.API/Program.cs @@ -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(); + builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { diff --git a/SurveyBackend/SurveyBackend.API/SurveyBackend.API.csproj b/SurveyBackend/SurveyBackend.API/SurveyBackend.API.csproj index 85458f2..54e0234 100644 --- a/SurveyBackend/SurveyBackend.API/SurveyBackend.API.csproj +++ b/SurveyBackend/SurveyBackend.API/SurveyBackend.API.csproj @@ -33,6 +33,7 @@ + diff --git a/SurveyBackend/SurveyBackend.sln b/SurveyBackend/SurveyBackend.sln index 56dba6f..6f4db84 100644 --- a/SurveyBackend/SurveyBackend.sln +++ b/SurveyBackend/SurveyBackend.sln @@ -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 diff --git a/SurveyLib b/SurveyLib index fa622c2..aae9d32 160000 --- a/SurveyLib +++ b/SurveyLib @@ -1 +1 @@ -Subproject commit fa622c270b206d505ad6d1dbd4df9cc31f35c3f1 +Subproject commit aae9d32397b784f115111f6a05c6dcdd1fc4f91f