Изменил пути у методов контроллеров + мелкий рефакторинг

This commit is contained in:
parent 8b137ca851
commit a0ef71a43d
7 changed files with 59 additions and 57 deletions

View File

@ -40,10 +40,10 @@ public class AutoGeneratedDailyReportController : ControllerBase
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet]
[Route("file")]
[ProducesResponseType(typeof(PhysicalFileResult), (int)HttpStatusCode.OK)]
[Route("export/excel")]
[ProducesResponseType(typeof(PhysicalFileResult), (int)HttpStatusCode.OK, "application/octet-stream")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> GenerateAsync([FromRoute] int idWell,
public async Task<IActionResult> ExportAsync([FromRoute] int idWell,
[Required] DateOnly reportDate,
CancellationToken cancellationToken)
{
@ -54,7 +54,7 @@ public class AutoGeneratedDailyReportController : ControllerBase
reportDate,
cancellationToken);
return File(reportFile.stream, "application/octet-stream", reportFile.fileName);
return File(reportFile.stream, reportFile.fileName);
}
/// <summary>

View File

@ -1,7 +1,6 @@
using AsbCloudApp.Data;
using AsbCloudApp.Data.DailyReport;
using AsbCloudApp.Exceptions;
using AsbCloudApp.Repositories;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
@ -10,6 +9,7 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
namespace AsbCloudWebApi.Controllers
{
@ -24,16 +24,13 @@ namespace AsbCloudWebApi.Controllers
{
private readonly IDailyReportService dailyReportService;
private readonly IWellService wellService;
private readonly IWellOperationRepository operationRepository;
public DailyReportController(
IDailyReportService dailyReportService,
IWellService wellService,
IWellOperationRepository operationRepository)
IWellService wellService)
{
this.dailyReportService = dailyReportService;
this.wellService = wellService;
this.operationRepository = operationRepository;
}
/// <summary>
@ -164,8 +161,9 @@ namespace AsbCloudWebApi.Controllers
/// <param name="date"></param>
/// <param name="token"></param>
/// <returns></returns>
[HttpGet("{date}/file")]
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
[HttpGet("{date}/export/excel")]
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK, "application/octet-stream")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> DownloadAsync(int idWell, DateOnly date, CancellationToken token)
{
if (!await UserHasAccesToWellAsync(idWell, token))
@ -175,13 +173,12 @@ namespace AsbCloudWebApi.Controllers
?? throw new ArgumentInvalidException($"Скважина c id:{idWell} не найдена", nameof(idWell));
var stream = await dailyReportService.MakeReportAsync(idWell, date, token);
if (stream is not null)
{
var fileName = $"Суточный рапорт по скважине {well.Caption} куст {well.Cluster}.xlsx";
return File(stream, "application/octet-stream", fileName);
}
else
if (stream is null)
return NoContent();
var fileName = $"Суточный рапорт по скважине {well.Caption} куст {well.Cluster}.xlsx";
return File(stream, fileName);
}
protected async Task<bool> UserHasAccesToWellAsync(int idWell, CancellationToken token)

View File

@ -38,18 +38,19 @@ namespace AsbCloudWebApi.Controllers
}
/// <summary>
/// Возвращает шаблон для заполнения строк плановой траектории
/// Возвращает excel шаблон для заполнения строк плановой траектории
/// </summary>
/// <returns>Запрашиваемый файл</returns>
[HttpGet]
[Route("template/file")]
[Route("template/excel")]
[AllowAnonymous]
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK,"application/octet-stream")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public IActionResult GetTemplate()
{
var stream = plannedTrajectoryImportService.GetTemplateFile();
var fileName = "ЕЦП_шаблон_файла_плановая_траектория.xlsx";
return File(stream, "application/octet-stream", fileName);
return File(stream, fileName);
}
/// <summary>
@ -59,8 +60,9 @@ namespace AsbCloudWebApi.Controllers
/// <param name="token"> Токен отмены задачи </param>
/// <returns>Запрашиваемый файл</returns>
[HttpGet]
[Route("file")]
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
[Route("export/excel")]
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK, "application/octet-stream")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> ExportAsync([FromRoute] int idWell, CancellationToken token)
{
if (!await CanUserAccessToWellAsync(idWell,
@ -68,7 +70,7 @@ namespace AsbCloudWebApi.Controllers
return Forbid();
var stream = await plannedTrajectoryImportService.ExportAsync(idWell, token);
var fileName = await plannedTrajectoryImportService.GetFileNameAsync(idWell, token);
return File(stream, "application/octet-stream", fileName);
return File(stream, fileName);
}
/// <summary>
@ -80,7 +82,7 @@ namespace AsbCloudWebApi.Controllers
/// <param name="token"> Токен отмены задачи </param>
/// <returns>количество успешно записанных строк в БД</returns>
[HttpPost]
[Route("file/{deleteBeforeImport}")]
[Route("import/excel/{deleteBeforeImport}")]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> ImportAsync(int idWell,
[FromForm] IFormFileCollection files,

View File

@ -100,8 +100,9 @@ namespace AsbCloudWebApi.Controllers
/// /// <param name="token"></param>
/// <returns></returns>
[HttpGet]
[Route("processMapReport/{wellId}/file")]
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
[Route("processMapReport/export/excel/{wellId}")]
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK, "application/octet-stream")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> GetReportFileAsync(int wellId, CancellationToken token)
{
var stream = await processMapReportService.MakeReportAsync(wellId, token);
@ -110,14 +111,12 @@ namespace AsbCloudWebApi.Controllers
var well = await wellService.GetOrDefaultAsync(wellId, token);
if (well is null)
return NoContent();
else
{
var fileName = $"РТК по скважине {well.Caption} куст {well.Cluster}.xlsx";
return File(stream, "application/octet-stream", fileName);
}
var fileName = $"РТК по скважине {well.Caption} куст {well.Cluster}.xlsx";
return File(stream, fileName);
}
else
return NoContent();
return NoContent();
}
/// <summary>
@ -170,13 +169,13 @@ namespace AsbCloudWebApi.Controllers
/// </summary>
/// <returns>Запрашиваемый файл</returns>
[HttpGet]
[Route("template/file")]
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
[Route("template/excel")]
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK, "application/octet-stream")]
public async Task<IActionResult> GetTemplateAsync(CancellationToken cancellationToken)
{
var stream = await processMapPlanImportService.GetExcelTemplateStreamAsync(cancellationToken);
var fileName = "ЕЦП_шаблон_файла_РТК.xlsx";
return File(stream, "application/octet-stream", fileName);
return File(stream, fileName);
}
/// <summary>
@ -188,7 +187,7 @@ namespace AsbCloudWebApi.Controllers
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost]
[Route("file/{idWell}/{options}")]
[Route("import/excel/{idWell}/{options}")]
public async Task<IActionResult> ImportAsync(int idWell,
int options,
[Required] IFormFile file,
@ -227,8 +226,9 @@ namespace AsbCloudWebApi.Controllers
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet]
[Route("file/{idWell}")]
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
[Route("export/excel/{idWell}")]
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK, "application/octet-stream")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> ExportAsync(int idWell, CancellationToken cancellationToken)
{
int? idUser = User.GetUserId();
@ -243,7 +243,7 @@ namespace AsbCloudWebApi.Controllers
var stream = await processMapPlanImportService.ExportAsync(idWell, cancellationToken);
var fileName = $"РТК-план по скважине {well.Caption} куст {well.Cluster}.xlsx";
return File(stream, "application/octet-stream", fileName);
return File(stream, fileName);
}
private async Task NotifyUsersBySignalR(int idWell, CancellationToken token)

View File

@ -8,6 +8,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
namespace AsbCloudWebApi.Controllers.SAUB
{
@ -121,9 +122,10 @@ namespace AsbCloudWebApi.Controllers.SAUB
/// <param name="token"> Токен отмены задачи </param>
/// <returns>Запрашиваемый файл</returns>
[HttpGet]
[Route("file")]
[Route("export/excel")]
[Permission]
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK, "application/octet-stream")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> ExportAsync(int? idWell, int? idCluster, CancellationToken token)
{
if (idCluster is null && idWell is null)
@ -151,7 +153,7 @@ namespace AsbCloudWebApi.Controllers.SAUB
var stream = await detectedOperationService.ExportAsync(idsWells, token);
var fileName = "operations.xlsx";
return File(stream, "application/octet-stream", fileName);
return File(stream, fileName);
}
}
}

View File

@ -6,6 +6,7 @@ using Microsoft.AspNetCore.SignalR;
using System.Threading.Tasks;
using System.Threading;
using System;
using Microsoft.AspNetCore.Http;
namespace AsbCloudWebApi.Controllers.SAUB
{
@ -41,8 +42,9 @@ namespace AsbCloudWebApi.Controllers.SAUB
/// <param name="endDate">конец интервала в формате: yyyy-MM-DD HH:mm</param>
/// <param name="token"></param>
/// <returns></returns>
[HttpGet("{idWell}/file")]
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
[HttpGet("{idWell}/export/csv")]
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK, "application/octet-stream")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> GetZippedCsv(int idWell, DateTime beginDate, DateTime endDate, CancellationToken token)
{
int? idCompany = User.GetCompanyId();
@ -58,7 +60,7 @@ namespace AsbCloudWebApi.Controllers.SAUB
var stream = await telemetryDataSaubService.GetZippedCsv(idWell, beginDate, endDate, token).ConfigureAwait(false);
var fileName = $"DataSaub idWell{idWell} {beginDate:yyyy-MM-DDTHH-mm} - {endDate:yyyy-MM-DDTHH-mm}.zip";
return File(stream, "application/octet-stream", fileName);
return File(stream, fileName);
}
}
}

View File

@ -1,5 +1,4 @@
using AsbCloudApp.Data;
using AsbCloudApp.Exceptions;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
@ -10,7 +9,6 @@ using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@ -284,7 +282,7 @@ namespace AsbCloudWebApi.Controllers
/// <returns></returns>
[HttpPost]
[Permission]
[Route("file/{options}")]
[Route("import/excel/{options}")]
public async Task<IActionResult> ImportAsync(int idWell,
[FromForm] IFormFileCollection files,
int options,
@ -324,12 +322,13 @@ namespace AsbCloudWebApi.Controllers
/// Создает excel файл с операциями по скважине
/// </summary>
/// <param name="idWell">id скважины</param>
/// <param name="token"> Токен отмены задачи </param>
/// <param name="token">Токен отмены задачи </param>
/// <returns>Запрашиваемый файл</returns>
[HttpGet]
[Route("file")]
[Route("export/excel")]
[Permission]
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK, "application/octet-stream")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> ExportAsync([FromRoute] int idWell, CancellationToken token)
{
int? idCompany = User.GetCompanyId();
@ -343,7 +342,7 @@ namespace AsbCloudWebApi.Controllers
var stream = wellOperationImportService.Export(idWell);
var fileName = await wellService.GetWellCaptionByIdAsync(idWell, token) + "_operations.xlsx";
return File(stream, "application/octet-stream", fileName);
return File(stream, fileName);
}
/// <summary>
@ -378,14 +377,14 @@ namespace AsbCloudWebApi.Controllers
/// </summary>
/// <returns>Запрашиваемый файл</returns>
[HttpGet]
[Route("template/file")]
[Route("template/excel")]
[AllowAnonymous]
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK, "application/octet-stream")]
public IActionResult GetTemplate()
{
var stream = wellOperationImportService.GetExcelTemplateStream();
var fileName = "ЕЦП_шаблон_файла_операций.xlsx";
return File(stream, "application/octet-stream", fileName);
return File(stream, fileName);
}
private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken token)