file service вынесен в bll. EsppDataController UploadTemplates
This commit is contained in:
@@ -21,6 +21,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
||||
EndProject
|
||||
Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{AB278172-BFB4-4D54-9022-2D2A5B3338D7}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PARR.BLL", "PARR.BLL\PARR.BLL.csproj", "{7BAB9170-743D-4542-8881-9B161EE81BB6}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -50,6 +52,10 @@ Global
|
||||
{AB278172-BFB4-4D54-9022-2D2A5B3338D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{AB278172-BFB4-4D54-9022-2D2A5B3338D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{AB278172-BFB4-4D54-9022-2D2A5B3338D7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{7BAB9170-743D-4542-8881-9B161EE81BB6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7BAB9170-743D-4542-8881-9B161EE81BB6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7BAB9170-743D-4542-8881-9B161EE81BB6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7BAB9170-743D-4542-8881-9B161EE81BB6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -1,19 +1,27 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using PARR.API.Contracts.V1;
|
||||
using PARR.API.Contracts.V1.Responses.Base;
|
||||
using PARR.API.Controllers.V1.Base;
|
||||
using PARR.API.Services.Interfaces;
|
||||
using PARR.BLL.Services.Interfaces;
|
||||
using PARR.BLL.Settings;
|
||||
|
||||
namespace PARR.API.Controllers.V1
|
||||
{
|
||||
public class EsppDataController : BaseApiController
|
||||
{
|
||||
private readonly IFileService fileService;
|
||||
private readonly StorageSettings storageSettings;
|
||||
|
||||
public EsppDataController(ILogger<EsppDataController> logger, IFileService fileService)
|
||||
public EsppDataController(
|
||||
ILogger<EsppDataController> logger,
|
||||
IFileService fileService,
|
||||
StorageSettings storageSettings
|
||||
)
|
||||
{
|
||||
Logger = logger;
|
||||
this.fileService = fileService;
|
||||
this.storageSettings = storageSettings;
|
||||
}
|
||||
|
||||
public ILogger<EsppDataController> Logger { get; }
|
||||
@@ -23,9 +31,24 @@ namespace PARR.API.Controllers.V1
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost(ApiRoutes.EsppData.UploadTemplates)]
|
||||
public IActionResult UploadTemplates([BindRequired] IFormFile file)
|
||||
public async Task<IActionResult> UploadTemplates([BindRequired] IFormFile file)
|
||||
{
|
||||
return Ok();
|
||||
if (!fileService.IsExtensionAllowed(file, storageSettings.EsppTemplates!.AllowedExtensions))
|
||||
return BadRequest(
|
||||
new Response(false,
|
||||
new List<ErrorModel> {
|
||||
new ErrorModel {
|
||||
Message = $"Недопустимое расширение файла. Разрешенные расширения: {string.Join(", ", storageSettings.EsppTemplates.AllowedExtensions)}"
|
||||
} }));
|
||||
|
||||
if (!fileService.IsNotExceededLimit(file, storageSettings.EsppTemplates.MaxFileSizeMb))
|
||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { FieldName = nameof(file), Message = $"Размер файла превышает {storageSettings.EsppTemplates.MaxFileSizeMb} МБайт" } }));
|
||||
|
||||
var uploadResult = await fileService.UploadAsync(file, storageSettings.EsppTemplates.TemplatePath);
|
||||
if (uploadResult == null)
|
||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = "Ошибка при сохранении файла" } }));
|
||||
|
||||
return Ok(new Response<string>("", true, new List<ErrorModel>(), $"Файл загружен."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
17
PARR.API/Domain/.gitkeep
Normal file
17
PARR.API/Domain/.gitkeep
Normal file
@@ -0,0 +1,17 @@
|
||||
Import System.Runtime.InteropServices
|
||||
|
||||
' In SDK-style projects such as this one, several assembly attributes that were historically
|
||||
' defined in this file are now automatically added during build and populated with
|
||||
' values defined in project properties. For details of which attributes are included
|
||||
' and how to customise this process see: https://aka.ms/assembly-info-properties
|
||||
|
||||
|
||||
' Setting ComVisible to false makes the types in this assembly not visible to COM
|
||||
' components. If you need to access a type in this assembly from COM, set the ComVisible
|
||||
' attribute to true on that type.
|
||||
|
||||
<Assembly: ComVisible(False)>
|
||||
|
||||
' The following GUID is for the ID of the typelib if this project is exposed to COM.
|
||||
|
||||
<Assembly: Guid("b369a17a-5b45-4482-9c44-bceb865427d2")>
|
||||
@@ -20,7 +20,7 @@ namespace PARR.API.Installers
|
||||
});
|
||||
|
||||
services.AddTransient<IClientService, ClientService>();
|
||||
services.AddTransient<IFileService, FileService>();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@ namespace PARR.API.Installers
|
||||
{
|
||||
public static void InstallSettings(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
var storageSettings = new StorageSettings();
|
||||
configuration.GetSection(nameof(StorageSettings)).Bind(storageSettings);
|
||||
services.AddSingleton(storageSettings);
|
||||
//var storageSettings = new StorageSettings();
|
||||
//configuration.GetSection(nameof(StorageSettings)).Bind(storageSettings);
|
||||
//services.AddSingleton(storageSettings);
|
||||
|
||||
//TODO: add other
|
||||
}
|
||||
|
||||
@@ -34,7 +34,12 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PARR.BLL\PARR.BLL.csproj" />
|
||||
<ProjectReference Include="..\PARR.DAL\PARR.DAL.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Domain\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace PARR.API.Domain
|
||||
namespace PARR.BLL.Domain
|
||||
{
|
||||
public class UploadResult
|
||||
{
|
||||
16
PARR.BLL/PARR.BLL.csproj
Normal file
16
PARR.BLL/PARR.BLL.csproj
Normal file
@@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
21
PARR.BLL/ParrBllInstaller.cs
Normal file
21
PARR.BLL/ParrBllInstaller.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using PARR.BLL.Services.Implementations;
|
||||
using PARR.BLL.Services.Interfaces;
|
||||
using PARR.BLL.Settings;
|
||||
|
||||
namespace PARR.BLL
|
||||
{
|
||||
public static class ParrBllInstaller
|
||||
{
|
||||
public static void InstallBllServices(this IServiceCollection services, IConfiguration configuration) {
|
||||
|
||||
var storageSettings = new StorageSettings();
|
||||
configuration.GetSection(nameof(StorageSettings)).Bind(storageSettings);
|
||||
services.AddSingleton(storageSettings);
|
||||
|
||||
|
||||
services.AddTransient<IFileService, FileService>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
using PARR.API.Domain;
|
||||
using PARR.API.Services.Interfaces;
|
||||
using PARR.API.Settings;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PARR.BLL.Domain;
|
||||
using PARR.BLL.Services.Interfaces;
|
||||
using PARR.BLL.Settings;
|
||||
|
||||
namespace PARR.API.Services.Implementations
|
||||
namespace PARR.BLL.Services.Implementations
|
||||
{
|
||||
public class FileService : IFileService
|
||||
internal class FileService : IFileService
|
||||
{
|
||||
private readonly StorageSettings storageSettings;
|
||||
private readonly ILogger<FileService> logger;
|
||||
@@ -1,6 +1,7 @@
|
||||
using PARR.API.Domain;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using PARR.BLL.Domain;
|
||||
|
||||
namespace PARR.API.Services.Interfaces
|
||||
namespace PARR.BLL.Services.Interfaces
|
||||
{
|
||||
public interface IFileService
|
||||
{
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace PARR.API.Settings
|
||||
namespace PARR.BLL.Settings
|
||||
{
|
||||
public class StorageSettings
|
||||
{
|
||||
Reference in New Issue
Block a user