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