forked from ddrilling/AsbCloudServer
ProcessMapPlanBaseController<TDto>.Parse() accepts single file
This commit is contained in:
parent
7867001610
commit
5c99d4ff57
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user