file service вынесен в bll. EsppDataController UploadTemplates

This commit is contained in:
Mikhail Trubnikov
2023-08-25 10:25:24 +10:00
parent 49ba6569b1
commit 8a48086f52
13 changed files with 122 additions and 17 deletions

View File

@@ -21,6 +21,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject EndProject
Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{AB278172-BFB4-4D54-9022-2D2A5B3338D7}" Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{AB278172-BFB4-4D54-9022-2D2A5B3338D7}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PARR.BLL", "PARR.BLL\PARR.BLL.csproj", "{7BAB9170-743D-4542-8881-9B161EE81BB6}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU 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}.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.ActiveCfg = Release|Any CPU
{AB278172-BFB4-4D54-9022-2D2A5B3338D7}.Release|Any CPU.Build.0 = 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 EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@@ -1,19 +1,27 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Mvc.ModelBinding;
using PARR.API.Contracts.V1; using PARR.API.Contracts.V1;
using PARR.API.Contracts.V1.Responses.Base;
using PARR.API.Controllers.V1.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 namespace PARR.API.Controllers.V1
{ {
public class EsppDataController : BaseApiController public class EsppDataController : BaseApiController
{ {
private readonly IFileService fileService; 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; Logger = logger;
this.fileService = fileService; this.fileService = fileService;
this.storageSettings = storageSettings;
} }
public ILogger<EsppDataController> Logger { get; } public ILogger<EsppDataController> Logger { get; }
@@ -23,9 +31,24 @@ namespace PARR.API.Controllers.V1
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[HttpPost(ApiRoutes.EsppData.UploadTemplates)] [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
View 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")>

View File

@@ -20,7 +20,7 @@ namespace PARR.API.Installers
}); });
services.AddTransient<IClientService, ClientService>(); services.AddTransient<IClientService, ClientService>();
services.AddTransient<IFileService, FileService>();
} }

View File

@@ -9,9 +9,9 @@ namespace PARR.API.Installers
{ {
public static void InstallSettings(this IServiceCollection services, IConfiguration configuration) public static void InstallSettings(this IServiceCollection services, IConfiguration configuration)
{ {
var storageSettings = new StorageSettings(); //var storageSettings = new StorageSettings();
configuration.GetSection(nameof(StorageSettings)).Bind(storageSettings); //configuration.GetSection(nameof(StorageSettings)).Bind(storageSettings);
services.AddSingleton(storageSettings); //services.AddSingleton(storageSettings);
//TODO: add other //TODO: add other
} }

View File

@@ -34,7 +34,12 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\PARR.BLL\PARR.BLL.csproj" />
<ProjectReference Include="..\PARR.DAL\PARR.DAL.csproj" /> <ProjectReference Include="..\PARR.DAL\PARR.DAL.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Domain\" />
</ItemGroup>
</Project> </Project>

View File

@@ -1,4 +1,4 @@
namespace PARR.API.Domain namespace PARR.BLL.Domain
{ {
public class UploadResult public class UploadResult
{ {

16
PARR.BLL/PARR.BLL.csproj Normal file
View 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>

View 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>();
}
}
}

View File

@@ -1,10 +1,12 @@
using PARR.API.Domain; using Microsoft.AspNetCore.Http;
using PARR.API.Services.Interfaces; using Microsoft.Extensions.Logging;
using PARR.API.Settings; 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 StorageSettings storageSettings;
private readonly ILogger<FileService> logger; private readonly ILogger<FileService> logger;

View File

@@ -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 public interface IFileService
{ {

View File

@@ -1,4 +1,4 @@
namespace PARR.API.Settings namespace PARR.BLL.Settings
{ {
public class StorageSettings public class StorageSettings
{ {

14
README.md Normal file
View File

@@ -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
```