file service вынесен в bll. EsppDataController UploadTemplates
This commit is contained in:
@@ -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>(), $"Файл загружен."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user