forked from ddrilling/AsbCloudServer
Merge branch 'dev' into feature/integration_tests
This commit is contained in:
commit
b2ad36a303
@ -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;
|
||||||
|
|
||||||
@ -52,12 +53,13 @@ public abstract class ProcessMapPlanBaseController<TDto> : ControllerBase
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
|
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
||||||
public async Task<IActionResult> InsertRange([FromRoute] int idWell, IEnumerable<TDto> dtos, CancellationToken token)
|
public async Task<IActionResult> InsertRange([FromRoute][Range(0,int.MaxValue)] int idWell, IEnumerable<TDto> dtos, CancellationToken token)
|
||||||
{
|
{
|
||||||
if (idWell == 0 || dtos.Any(d => d.IdWell != idWell))
|
|
||||||
return this.ValidationBadRequest(nameof(dtos), "all dtos should contain same idWell");
|
|
||||||
|
|
||||||
var idUser = await AssertUserHasAccessToWell(idWell, token);
|
var idUser = await AssertUserHasAccessToWell(idWell, token);
|
||||||
|
|
||||||
|
foreach (var dto in dtos)
|
||||||
|
dto.IdWell = idWell;
|
||||||
|
|
||||||
var result = await repository.InsertRange(idUser, dtos, token);
|
var result = await repository.InsertRange(idUser, dtos, token);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
@ -74,11 +76,11 @@ public abstract class ProcessMapPlanBaseController<TDto> : ControllerBase
|
|||||||
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
||||||
public async Task<IActionResult> ClearAndInsertRange([FromRoute] int idWell, IEnumerable<TDto> dtos, CancellationToken token)
|
public async Task<IActionResult> ClearAndInsertRange([FromRoute] int idWell, IEnumerable<TDto> dtos, CancellationToken token)
|
||||||
{
|
{
|
||||||
if (idWell == 0 || dtos.Any(d => d.IdWell != idWell))
|
|
||||||
return this.ValidationBadRequest(nameof(dtos), "all dtos should contain same idWell");
|
|
||||||
|
|
||||||
var idUser = await AssertUserHasAccessToWell(idWell, token);
|
var idUser = await AssertUserHasAccessToWell(idWell, token);
|
||||||
|
|
||||||
|
foreach (var dto in dtos)
|
||||||
|
dto.IdWell = idWell;
|
||||||
|
|
||||||
var request = new ProcessMapPlanBaseRequestWithWell(idWell);
|
var request = new ProcessMapPlanBaseRequestWithWell(idWell);
|
||||||
var result = await repository.ClearAndInsertRange(idUser, request, dtos, token);
|
var result = await repository.ClearAndInsertRange(idUser, request, dtos, token);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
@ -188,15 +190,14 @@ public abstract class ProcessMapPlanBaseController<TDto> : ControllerBase
|
|||||||
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
||||||
public async Task<IActionResult> UpdateOrInsertRange([FromRoute] int idWell, IEnumerable<TDto> dtos, CancellationToken token)
|
public async Task<IActionResult> UpdateOrInsertRange([FromRoute] int idWell, IEnumerable<TDto> dtos, CancellationToken token)
|
||||||
{
|
{
|
||||||
var first = dtos.FirstOrDefault();
|
if (!dtos.Any())
|
||||||
if (first is null)
|
|
||||||
return NoContent();
|
return NoContent();
|
||||||
|
|
||||||
if (idWell == 0 || dtos.Any(d => d.IdWell != idWell))
|
|
||||||
return this.ValidationBadRequest(nameof(dtos), "all dtos should contain same idWell");
|
|
||||||
|
|
||||||
var idUser = await AssertUserHasAccessToWell(idWell, token);
|
var idUser = await AssertUserHasAccessToWell(idWell, token);
|
||||||
|
|
||||||
|
foreach (var dto in dtos)
|
||||||
|
dto.IdWell = idWell;
|
||||||
|
|
||||||
var result = await repository.UpdateOrInsertRange(idUser, dtos, token);
|
var result = await repository.UpdateOrInsertRange(idUser, dtos, token);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
@ -205,28 +206,31 @@ 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
|
||||||
{
|
{
|
||||||
var dto = parserService.Parse(stream, IParserOptionsRequest.Empty());
|
var dto = parserService.Parse(stream, IParserOptionsRequest.Empty());
|
||||||
|
foreach (var item in dto.Item)
|
||||||
|
item.Item.IdWell = idWell;
|
||||||
|
|
||||||
return Ok(dto);
|
return Ok(dto);
|
||||||
}
|
}
|
||||||
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