diff --git a/AsbCloudWebApi/Controllers/Interfaces/IControllerWithParser.cs b/AsbCloudWebApi/Controllers/Interfaces/IControllerWithParser.cs index d11ac201..e47d644b 100644 --- a/AsbCloudWebApi/Controllers/Interfaces/IControllerWithParser.cs +++ b/AsbCloudWebApi/Controllers/Interfaces/IControllerWithParser.cs @@ -1,13 +1,22 @@ -using System.IO; +using System.Threading; +using System.Threading.Tasks; using AsbCloudApp.Data; +using AsbCloudApp.Requests.ParserOptions; +using AsbCloudApp.Services; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; namespace AsbCloudWebApi.Controllers.Interfaces; -public interface IControllerWithParser +public interface IWellControllerWithParser where TDto : class, IId + where TOptions : class, IParserOptionsRequest { - ActionResult> Parse(Stream file, TOptions options); + IParserService ParserService { get; } + + Task>> Parse(int idWell, + [FromForm] IFormFileCollection files, + CancellationToken token); IActionResult GetTemplate(); } \ No newline at end of file diff --git a/AsbCloudWebApi/Controllers/ProcessMapPlan/ProcessMapPlanBaseController.cs b/AsbCloudWebApi/Controllers/ProcessMapPlan/ProcessMapPlanBaseController.cs index ca54ef62..f630059c 100644 --- a/AsbCloudWebApi/Controllers/ProcessMapPlan/ProcessMapPlanBaseController.cs +++ b/AsbCloudWebApi/Controllers/ProcessMapPlan/ProcessMapPlanBaseController.cs @@ -9,7 +9,6 @@ using Microsoft.AspNetCore.Http; using AsbCloudApp.Exceptions; using AsbCloudApp.Requests; using System; -using System.IO; using AsbCloudApp.Services; using System.Linq; using AsbCloudApp.Data; @@ -26,12 +25,11 @@ namespace AsbCloudWebApi.Controllers.ProcessMapPlan; [Route("api/well/{idWell}/[controller]")] [Authorize] public abstract class ProcessMapPlanBaseController : ControllerBase, - IControllerWithParser + IWellControllerWithParser where TDto : ProcessMapPlanBaseDto { private readonly IChangeLogRepository repository; private readonly IWellService wellService; - private readonly IParserService parserService; protected ProcessMapPlanBaseController(IChangeLogRepository repository, IWellService wellService, @@ -40,24 +38,14 @@ public abstract class ProcessMapPlanBaseController : ControllerBase, { this.repository = repository; this.wellService = wellService; - parserService = parserFactory.Create(idParserService); + + ParserService = parserFactory.Create(idParserService); } + public IParserService ParserService { get; } + protected abstract string TemplateFileName { get; } - - ActionResult> IControllerWithParser.Parse(Stream file, IParserOptionsRequest options) - { - try - { - var parserResult = parserService.Parse(file, options); - return Ok(parserResult); - } - catch (FileFormatException ex) - { - return this.ValidationBadRequest("files", ex.Message); - } - } - + /// /// Добавление /// @@ -246,7 +234,7 @@ public abstract class ProcessMapPlanBaseController : ControllerBase, [ProducesResponseType(StatusCodes.Status204NoContent)] public IActionResult GetTemplate() { - var stream = parserService.GetTemplateFile(); + var stream = ParserService.GetTemplateFile(); return File(stream, "application/octet-stream", TemplateFileName); } diff --git a/AsbCloudWebApi/Controllers/Trajectory/TrajectoryEditableController.cs b/AsbCloudWebApi/Controllers/Trajectory/TrajectoryEditableController.cs index 30251923..d96b1491 100644 --- a/AsbCloudWebApi/Controllers/Trajectory/TrajectoryEditableController.cs +++ b/AsbCloudWebApi/Controllers/Trajectory/TrajectoryEditableController.cs @@ -6,7 +6,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; -using System.IO; using System.Threading; using System.Threading.Tasks; using AsbCloudApp.Data; @@ -23,10 +22,9 @@ namespace AsbCloudWebApi.Controllers.Trajectory [ApiController] [Authorize] public abstract class TrajectoryEditableController : TrajectoryController, - IControllerWithParser + IWellControllerWithParser where TDto : TrajectoryGeoDto - { - private readonly IParserService parserService; + { private readonly ITrajectoryEditableRepository trajectoryRepository; protected TrajectoryEditableController(IWellService wellService, @@ -39,25 +37,13 @@ namespace AsbCloudWebApi.Controllers.Trajectory trajectoryExportService, trajectoryRepository) { - parserService = parserServiceFactory.Create(idParserService); this.trajectoryRepository = trajectoryRepository; - } - - ActionResult> IControllerWithParser.Parse(Stream file, - IParserOptionsRequest options) - { - try - { - var parserResult = parserService.Parse(file, options); - return Ok(parserResult); - } - catch (FileFormatException ex) - { - return this.ValidationBadRequest("files", ex.Message); - } + ParserService = parserServiceFactory.Create(idParserService); } - /// + public IParserService ParserService { get; } + + /// /// Возвращает excel шаблон для заполнения строк траектории /// /// Запрашиваемый файл @@ -67,7 +53,7 @@ namespace AsbCloudWebApi.Controllers.Trajectory [ProducesResponseType(StatusCodes.Status204NoContent)] public IActionResult GetTemplate() { - var stream = parserService.GetTemplateFile(); + var stream = ParserService.GetTemplateFile(); return File(stream, "application/octet-stream", fileName); } diff --git a/AsbCloudWebApi/Extensions.cs b/AsbCloudWebApi/Extensions.cs index 489d6149..b78a9745 100644 --- a/AsbCloudWebApi/Extensions.cs +++ b/AsbCloudWebApi/Extensions.cs @@ -105,7 +105,7 @@ public static class Extensions /// /// public static ActionResult> ParseExcelFile( - this IControllerWithParser controller, + this IWellControllerWithParser controller, IFormFileCollection files, TOptions options) where TDto : class, IId @@ -120,6 +120,6 @@ public static class Extensions var stream = file.OpenReadStream(); - return controller.Parse(stream, options); + return controller.ParserService.Parse(stream, options); } } \ No newline at end of file