template controller
This commit is contained in:
@@ -10,6 +10,7 @@ namespace PARR.API.Controllers.V1
|
||||
{
|
||||
public class EsppDataController : BaseApiController
|
||||
{
|
||||
private readonly ILogger<EsppDataController> logger;
|
||||
private readonly IFileService fileService;
|
||||
private readonly StorageSettings storageSettings;
|
||||
|
||||
@@ -19,36 +20,36 @@ namespace PARR.API.Controllers.V1
|
||||
StorageSettings storageSettings
|
||||
)
|
||||
{
|
||||
Logger = logger;
|
||||
this.logger = logger;
|
||||
this.fileService = fileService;
|
||||
this.storageSettings = storageSettings;
|
||||
}
|
||||
|
||||
public ILogger<EsppDataController> Logger { get; }
|
||||
// UploadTemplates - неактуально, так как стали брать данные с RabbitMQ
|
||||
|
||||
/// <summary>
|
||||
/// Загрузить файл списка шаблонов полученных из ЕСПП в формате csv
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost(ApiRoutes.EsppData.UploadTemplates)]
|
||||
public async Task<IActionResult> UploadTemplates([BindRequired] IFormFile file)
|
||||
{
|
||||
if (!fileService.IsExtensionAllowed(file, storageSettings.EsppTemplates!.AllowedExtensions))
|
||||
return BadRequest(
|
||||
new Response(false,
|
||||
new List<ErrorModel> {
|
||||
new ErrorModel {
|
||||
Message = $"Недопустимое расширение файла. Разрешенные расширения: {string.Join(", ", storageSettings.EsppTemplates.AllowedExtensions)}"
|
||||
} }));
|
||||
///// <summary>
|
||||
///// Загрузить файл списка шаблонов полученных из ЕСПП в формате csv
|
||||
///// </summary>
|
||||
///// <returns></returns>
|
||||
//[HttpPost(ApiRoutes.EsppData.UploadTemplates)]
|
||||
//public async Task<IActionResult> UploadTemplates([BindRequired] IFormFile file)
|
||||
//{
|
||||
// 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} МБайт" } }));
|
||||
// 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 = "Ошибка при сохранении файла" } }));
|
||||
// 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>(), $"Файл загружен."));
|
||||
}
|
||||
// return Ok(new Response<string>("", true, new List<ErrorModel>(), $"Файл загружен."));
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user