diff --git a/PARR.API.sln b/PARR.API.sln index a2df5e56..b8a6d906 100644 --- a/PARR.API.sln +++ b/PARR.API.sln @@ -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 diff --git a/PARR.API/Controllers/V1/EsppDataController.cs b/PARR.API/Controllers/V1/EsppDataController.cs index 81fb4597..666d0b56 100644 --- a/PARR.API/Controllers/V1/EsppDataController.cs +++ b/PARR.API/Controllers/V1/EsppDataController.cs @@ -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 logger, IFileService fileService) + public EsppDataController( + ILogger logger, + IFileService fileService, + StorageSettings storageSettings + ) { Logger = logger; this.fileService = fileService; + this.storageSettings = storageSettings; } public ILogger Logger { get; } @@ -23,9 +31,24 @@ namespace PARR.API.Controllers.V1 /// /// [HttpPost(ApiRoutes.EsppData.UploadTemplates)] - public IActionResult UploadTemplates([BindRequired] IFormFile file) + public async Task UploadTemplates([BindRequired] IFormFile file) { - return Ok(); + if (!fileService.IsExtensionAllowed(file, storageSettings.EsppTemplates!.AllowedExtensions)) + return BadRequest( + new Response(false, + new List { + new ErrorModel { + Message = $"Недопустимое расширение файла. Разрешенные расширения: {string.Join(", ", storageSettings.EsppTemplates.AllowedExtensions)}" + } })); + + if (!fileService.IsNotExceededLimit(file, storageSettings.EsppTemplates.MaxFileSizeMb)) + return BadRequest(new Response(false, new List { 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 { new ErrorModel { Message = "Ошибка при сохранении файла" } })); + + return Ok(new Response("", true, new List(), $"Файл загружен.")); } } } diff --git a/PARR.API/Domain/.gitkeep b/PARR.API/Domain/.gitkeep new file mode 100644 index 00000000..488dff50 --- /dev/null +++ b/PARR.API/Domain/.gitkeep @@ -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. + + + +' The following GUID is for the ID of the typelib if this project is exposed to COM. + + diff --git a/PARR.API/Installers/ApiServicesInstaller.cs b/PARR.API/Installers/ApiServicesInstaller.cs index 28f21d57..4ff3bc14 100644 --- a/PARR.API/Installers/ApiServicesInstaller.cs +++ b/PARR.API/Installers/ApiServicesInstaller.cs @@ -20,7 +20,7 @@ namespace PARR.API.Installers }); services.AddTransient(); - services.AddTransient(); + } diff --git a/PARR.API/Installers/SettingsInstaller.cs b/PARR.API/Installers/SettingsInstaller.cs index 0a878fa6..b63bbf70 100644 --- a/PARR.API/Installers/SettingsInstaller.cs +++ b/PARR.API/Installers/SettingsInstaller.cs @@ -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 } diff --git a/PARR.API/PARR.API.csproj b/PARR.API/PARR.API.csproj index d839331e..57fcfc78 100644 --- a/PARR.API/PARR.API.csproj +++ b/PARR.API/PARR.API.csproj @@ -34,7 +34,12 @@ + + + + + diff --git a/PARR.API/Domain/UploadResult.cs b/PARR.BLL/Domain/UploadResult.cs similarity index 83% rename from PARR.API/Domain/UploadResult.cs rename to PARR.BLL/Domain/UploadResult.cs index 13d66801..a0bb8f9d 100644 --- a/PARR.API/Domain/UploadResult.cs +++ b/PARR.BLL/Domain/UploadResult.cs @@ -1,4 +1,4 @@ -namespace PARR.API.Domain +namespace PARR.BLL.Domain { public class UploadResult { diff --git a/PARR.BLL/PARR.BLL.csproj b/PARR.BLL/PARR.BLL.csproj new file mode 100644 index 00000000..1c2edf9c --- /dev/null +++ b/PARR.BLL/PARR.BLL.csproj @@ -0,0 +1,16 @@ + + + + net7.0 + enable + enable + + + + + + + + + + diff --git a/PARR.BLL/ParrBllInstaller.cs b/PARR.BLL/ParrBllInstaller.cs new file mode 100644 index 00000000..782a45e0 --- /dev/null +++ b/PARR.BLL/ParrBllInstaller.cs @@ -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(); + } + } +} diff --git a/PARR.API/Services/Implementations/FileService.cs b/PARR.BLL/Services/Implementations/FileService.cs similarity index 93% rename from PARR.API/Services/Implementations/FileService.cs rename to PARR.BLL/Services/Implementations/FileService.cs index c8c74a8a..ee42578f 100644 --- a/PARR.API/Services/Implementations/FileService.cs +++ b/PARR.BLL/Services/Implementations/FileService.cs @@ -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 logger; diff --git a/PARR.API/Services/Interfaces/IFileService.cs b/PARR.BLL/Services/Interfaces/IFileService.cs similarity index 88% rename from PARR.API/Services/Interfaces/IFileService.cs rename to PARR.BLL/Services/Interfaces/IFileService.cs index cd54edd2..1ffc8563 100644 --- a/PARR.API/Services/Interfaces/IFileService.cs +++ b/PARR.BLL/Services/Interfaces/IFileService.cs @@ -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 { diff --git a/PARR.API/Settings/StorageSettings.cs b/PARR.BLL/Settings/StorageSettings.cs similarity index 95% rename from PARR.API/Settings/StorageSettings.cs rename to PARR.BLL/Settings/StorageSettings.cs index 87fca1c8..c5c0ba24 100644 --- a/PARR.API/Settings/StorageSettings.cs +++ b/PARR.BLL/Settings/StorageSettings.cs @@ -1,4 +1,4 @@ -namespace PARR.API.Settings +namespace PARR.BLL.Settings { public class StorageSettings { diff --git a/README.md b/README.md new file mode 100644 index 00000000..521dc1c8 --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# API PARR + +## Настройка хранилища + +``` +#dev +\\dvgd-appfs-01\parr_storage_dev +parruserdev +P@ssDevParr202MM + +#dev подключение хранилища +net use w: /d /y +net use w: \\dvgd-appfs-01\parr_storage_dev /USER:parruserdev P@ssDevParr202MM /PERSISTENT:YES +```