ProcessMapPlanBaseController<TDto>.Parse() accepts single file

This commit is contained in:
ngfrolov 2024-03-11 14:50:43 +05:00
parent 7867001610
commit 5c99d4ff57
Signed by untrusted user who does not match committer: ng.frolov
GPG Key ID: E99907A0357B29A7
2 changed files with 19 additions and 4 deletions

View File

@ -15,6 +15,7 @@ using AsbCloudApp.Data;
using AsbCloudApp.Requests.ParserOptions;
using AsbCloudInfrastructure.Services.Parser;
using AsbCloudApp.Data.ProcessMaps;
using System.ComponentModel.DataAnnotations;
namespace AsbCloudWebApi.Controllers.ProcessMaps;
@ -205,19 +206,19 @@ public abstract class ProcessMapPlanBaseController<TDto> : ControllerBase
/// Импорт РТК из excel (xlsx) файла
/// </summary>
/// <param name="idWell"></param>
/// <param name="files"></param>
/// <param name="file"></param>
/// <param name="token"></param>
/// <returns></returns>
[HttpPost("parse")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
public async Task<ActionResult<ParserResultDto<TDto>>> Parse(int idWell,
[FromForm] IFormFileCollection files,
[Required] IFormFile file,
CancellationToken token)
{
await AssertUserHasAccessToWell(idWell, token);
var stream = files.GetExcelFile();
var stream = file.GetExcelFile();
try
{
@ -226,7 +227,7 @@ public abstract class ProcessMapPlanBaseController<TDto> : ControllerBase
}
catch (FileFormatException ex)
{
return this.ValidationBadRequest(nameof(files), ex.Message);
return this.ValidationBadRequest(nameof(file), ex.Message);
}
}

View File

@ -113,4 +113,18 @@ public static class Extensions
return file.OpenReadStream();
}
/// <summary>
/// Получение Excel
/// </summary>
/// <param name="files"></param>
/// <returns></returns>
/// <exception cref="ArgumentInvalidException"></exception>
public static Stream GetExcelFile(this IFormFile file)
{
if (Path.GetExtension(file.FileName).ToLower() != ".xlsx")
throw new ArgumentInvalidException(nameof(file), "Требуется .xlsx файл.");
return file.OpenReadStream();
}
}