forked from ddrilling/AsbCloudServer
replace BadRequest by ValidationBadRequest
This commit is contained in:
parent
1f9dc2b061
commit
4a6bc2c747
@ -88,10 +88,11 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// <returns>id</returns>
|
/// <returns>id</returns>
|
||||||
[HttpPost("range")]
|
[HttpPost("range")]
|
||||||
[Permission]
|
[Permission]
|
||||||
|
[ProducesResponseType(typeof(ValidationProblemDetails), (int)System.Net.HttpStatusCode.BadRequest)]
|
||||||
public virtual async Task<ActionResult<int>> InsertRangeAsync([FromBody] IEnumerable<T> values, CancellationToken token)
|
public virtual async Task<ActionResult<int>> InsertRangeAsync([FromBody] IEnumerable<T> values, CancellationToken token)
|
||||||
{
|
{
|
||||||
if (!values.Any())
|
if (!values.Any())
|
||||||
return BadRequest("there is no values to add");
|
return this.ValidationBadRequest(nameof(values), "there is no values to add");
|
||||||
|
|
||||||
if (InsertForbidAsync is not null)
|
if (InsertForbidAsync is not null)
|
||||||
foreach (var value in values)
|
foreach (var value in values)
|
||||||
@ -110,6 +111,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// <returns>1 - успешно отредактировано, 0 - нет</returns>
|
/// <returns>1 - успешно отредактировано, 0 - нет</returns>
|
||||||
[HttpPut]
|
[HttpPut]
|
||||||
[Permission]
|
[Permission]
|
||||||
|
[ProducesResponseType(typeof(ValidationProblemDetails), (int)System.Net.HttpStatusCode.BadRequest)]
|
||||||
public virtual async Task<ActionResult<int>> UpdateAsync([FromBody] T value, CancellationToken token)
|
public virtual async Task<ActionResult<int>> UpdateAsync([FromBody] T value, CancellationToken token)
|
||||||
{
|
{
|
||||||
if (UpdateForbidAsync is not null && await UpdateForbidAsync(value, token))
|
if (UpdateForbidAsync is not null && await UpdateForbidAsync(value, token))
|
||||||
@ -117,7 +119,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
|
|
||||||
var result = await service.UpdateAsync(value, token).ConfigureAwait(false);
|
var result = await service.UpdateAsync(value, token).ConfigureAwait(false);
|
||||||
if (result == ICrudRepository<T>.ErrorIdNotFound)
|
if (result == ICrudRepository<T>.ErrorIdNotFound)
|
||||||
return BadRequest($"id:{value.Id} does not exist in the db");
|
return this.ValidationBadRequest(nameof(value.Id), $"id:{value.Id} does not exist");
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +81,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// <returns>количество успешно записанных строк в БД</returns>
|
/// <returns>количество успешно записанных строк в БД</returns>
|
||||||
[HttpPost("import/{deleteBeforeImport}")]
|
[HttpPost("import/{deleteBeforeImport}")]
|
||||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
[ProducesResponseType(typeof(ValidationProblemDetails), (int)System.Net.HttpStatusCode.BadRequest)]
|
||||||
public async Task<IActionResult> ImportAsync(int idWell,
|
public async Task<IActionResult> ImportAsync(int idWell,
|
||||||
[FromForm] IFormFileCollection files,
|
[FromForm] IFormFileCollection files,
|
||||||
bool deleteBeforeImport,
|
bool deleteBeforeImport,
|
||||||
@ -93,10 +94,10 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
token).ConfigureAwait(false))
|
token).ConfigureAwait(false))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
if (files.Count < 1)
|
if (files.Count < 1)
|
||||||
return BadRequest("нет файла");
|
return this.ValidationBadRequest(nameof(files), "нет файла");
|
||||||
var file = files[0];
|
var file = files[0];
|
||||||
if (Path.GetExtension(file.FileName).ToLower() != ".xlsx")
|
if (Path.GetExtension(file.FileName).ToLower() != ".xlsx")
|
||||||
return BadRequest("Требуется xlsx файл.");
|
return this.ValidationBadRequest(nameof(files), "Требуется xlsx файл.");
|
||||||
using Stream stream = file.OpenReadStream();
|
using Stream stream = file.OpenReadStream();
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -106,7 +107,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
}
|
}
|
||||||
catch (FileFormatException ex)
|
catch (FileFormatException ex)
|
||||||
{
|
{
|
||||||
return BadRequest(ex.Message);
|
return this.ValidationBadRequest(nameof(files), ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,11 +64,12 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[Obsolete("use GetByUidAsync(..) instead")]
|
[Obsolete("use GetByUidAsync(..) instead")]
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
[ProducesResponseType(typeof(IEnumerable<ProcessMapPlanDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(IEnumerable<ProcessMapPlanDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
[ProducesResponseType(typeof(ValidationProblemDetails), (int)System.Net.HttpStatusCode.BadRequest)]
|
||||||
public IActionResult GetByTelemetry(string uid, DateTime updateFrom, CancellationToken token)
|
public IActionResult GetByTelemetry(string uid, DateTime updateFrom, CancellationToken token)
|
||||||
{
|
{
|
||||||
var idWell = telemetryService.GetIdWellByTelemetryUid(uid);
|
var idWell = telemetryService.GetIdWellByTelemetryUid(uid);
|
||||||
if (idWell is null)
|
if (idWell is null)
|
||||||
return BadRequest($"Wrong uid {uid}");
|
return this.ValidationBadRequest(nameof(uid), $"Wrong uid {uid}");
|
||||||
return Ok(Enumerable.Empty<ProcessMapPlanDto>());
|
return Ok(Enumerable.Empty<ProcessMapPlanDto>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,11 +83,12 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[HttpGet("/api/telemetry/{uid}/processMap")]
|
[HttpGet("/api/telemetry/{uid}/processMap")]
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
[ProducesResponseType(typeof(IEnumerable<ProcessMapPlanDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(IEnumerable<ProcessMapPlanDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
[ProducesResponseType(typeof(ValidationProblemDetails), (int)System.Net.HttpStatusCode.BadRequest)]
|
||||||
public async Task<IActionResult> GetByUidAsync(string uid, DateTime updateFrom, CancellationToken token)
|
public async Task<IActionResult> GetByUidAsync(string uid, DateTime updateFrom, CancellationToken token)
|
||||||
{
|
{
|
||||||
var idWell = telemetryService.GetIdWellByTelemetryUid(uid);
|
var idWell = telemetryService.GetIdWellByTelemetryUid(uid);
|
||||||
if (idWell is null)
|
if (idWell is null)
|
||||||
return BadRequest($"Wrong uid {uid}");
|
return this.ValidationBadRequest(nameof(uid), $"Wrong uid {uid}");
|
||||||
|
|
||||||
var dto = await service.GetAllAsync((int)idWell,
|
var dto = await service.GetAllAsync((int)idWell,
|
||||||
updateFrom, token);
|
updateFrom, token);
|
||||||
@ -191,6 +193,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost("import/{idWell}/{options}")]
|
[HttpPost("import/{idWell}/{options}")]
|
||||||
|
[ProducesResponseType(typeof(ValidationProblemDetails), (int)System.Net.HttpStatusCode.BadRequest)]
|
||||||
public async Task<IActionResult> ImportAsync(int idWell,
|
public async Task<IActionResult> ImportAsync(int idWell,
|
||||||
int options,
|
int options,
|
||||||
[Required] IFormFile file,
|
[Required] IFormFile file,
|
||||||
@ -205,7 +208,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
if (Path.GetExtension(file.FileName).ToLower() != ".xlsx")
|
if (Path.GetExtension(file.FileName).ToLower() != ".xlsx")
|
||||||
return BadRequest("Требуется xlsx файл.");
|
return this.ValidationBadRequest(nameof(file), "Требуется xlsx файл.");
|
||||||
|
|
||||||
using Stream stream = file.OpenReadStream();
|
using Stream stream = file.OpenReadStream();
|
||||||
|
|
||||||
@ -219,7 +222,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
}
|
}
|
||||||
catch (FileFormatException ex)
|
catch (FileFormatException ex)
|
||||||
{
|
{
|
||||||
return BadRequest(ex.Message);
|
return this.ValidationBadRequest(nameof(file), ex.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok();
|
return Ok();
|
||||||
|
@ -59,10 +59,11 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet("schema/{typeName}")]
|
[HttpGet("schema/{typeName}")]
|
||||||
[ProducesResponseType(typeof(IEnumerable<string>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(IEnumerable<string>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
[ProducesResponseType(typeof(ValidationProblemDetails), (int)System.Net.HttpStatusCode.BadRequest)]
|
||||||
public IActionResult GetSchema(string typeName)
|
public IActionResult GetSchema(string typeName)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(typeName))
|
if (string.IsNullOrEmpty(typeName))
|
||||||
return BadRequest("require typeName");
|
return this.ValidationBadRequest(nameof(typeName), "require typeName");
|
||||||
|
|
||||||
var type = RuntimeTypeModel.Default
|
var type = RuntimeTypeModel.Default
|
||||||
.GetTypes()
|
.GetTypes()
|
||||||
|
@ -125,6 +125,7 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
|||||||
[Permission]
|
[Permission]
|
||||||
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK, "application/octet-stream")]
|
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK, "application/octet-stream")]
|
||||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||||
|
[ProducesResponseType(typeof(ValidationProblemDetails), (int)System.Net.HttpStatusCode.BadRequest)]
|
||||||
public async Task<IActionResult> ExportAsync(int? idWell, int? idCluster, CancellationToken token)
|
public async Task<IActionResult> ExportAsync(int? idWell, int? idCluster, CancellationToken token)
|
||||||
{
|
{
|
||||||
if (idCluster is null && idWell is null)
|
if (idCluster is null && idWell is null)
|
||||||
|
@ -33,6 +33,7 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Permission]
|
[Permission]
|
||||||
[ProducesResponseType(typeof(PaginationContainer<MessageDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(PaginationContainer<MessageDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
[ProducesResponseType(typeof(ValidationProblemDetails), (int)System.Net.HttpStatusCode.BadRequest)]
|
||||||
public async Task<IActionResult> GetMessagesAsync(
|
public async Task<IActionResult> GetMessagesAsync(
|
||||||
[FromRoute] int idWell,
|
[FromRoute] int idWell,
|
||||||
[FromQuery] MessageRequestBase request,
|
[FromQuery] MessageRequestBase request,
|
||||||
@ -43,7 +44,7 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
|||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
if (request.Take > 1024)
|
if (request.Take > 1024)
|
||||||
return BadRequest("limit mast be less then 1024");
|
return this.ValidationBadRequest(nameof(request.Take), "limit mast be less then 1024");
|
||||||
|
|
||||||
var requestToService = new MessageRequest(request, idWell);
|
var requestToService = new MessageRequest(request, idWell);
|
||||||
|
|
||||||
|
@ -51,6 +51,7 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
|||||||
[HttpPost("api/well/{idWell}/setpoints")]
|
[HttpPost("api/well/{idWell}/setpoints")]
|
||||||
[Permission]
|
[Permission]
|
||||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
[ProducesResponseType(typeof(ValidationProblemDetails), (int)System.Net.HttpStatusCode.BadRequest)]
|
||||||
public async Task<IActionResult> InsertAsync(int idWell, SetpointsRequestDto setpoints, CancellationToken token)
|
public async Task<IActionResult> InsertAsync(int idWell, SetpointsRequestDto setpoints, CancellationToken token)
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
int? idCompany = User.GetCompanyId();
|
||||||
@ -70,10 +71,10 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
|||||||
if (setpoints is null
|
if (setpoints is null
|
||||||
|| setpoints.ObsolescenceSec > ObsolescenceSecMax
|
|| setpoints.ObsolescenceSec > ObsolescenceSecMax
|
||||||
|| setpoints.ObsolescenceSec < ObsolescenceSecMin)
|
|| setpoints.ObsolescenceSec < ObsolescenceSecMin)
|
||||||
return BadRequest("Wrong ObsolescenceSec");
|
return this.ValidationBadRequest(nameof(setpoints.ObsolescenceSec), "Wrong ObsolescenceSec");
|
||||||
|
|
||||||
if (!setpoints.Setpoints.Any())
|
if (!setpoints.Setpoints.Any())
|
||||||
return BadRequest("Wrong setpoints count");
|
return this.ValidationBadRequest(nameof(setpoints.Setpoints), "Wrong setpoints count");
|
||||||
|
|
||||||
var result = await setpointsService.InsertAsync(setpoints, token)
|
var result = await setpointsService.InsertAsync(setpoints, token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
@ -8,6 +8,7 @@ using System.Collections.Generic;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using AsbCloudApp.Repositories;
|
using AsbCloudApp.Repositories;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
namespace AsbCloudWebApi.Controllers.SAUB
|
namespace AsbCloudWebApi.Controllers.SAUB
|
||||||
{
|
{
|
||||||
@ -47,11 +48,8 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost("{uid}")]
|
[HttpPost("{uid}")]
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
public async Task<IActionResult> PostDataAsync(string uid, [FromBody] TelemetryWirelineRunOutBaseDto dto, CancellationToken token)
|
public async Task<IActionResult> PostDataAsync(string uid, [FromBody, Required] TelemetryWirelineRunOutBaseDto dto, CancellationToken token)
|
||||||
{
|
{
|
||||||
if (dto is null)
|
|
||||||
return BadRequest("Dto shouldn't be null");
|
|
||||||
|
|
||||||
var data = await repository.AddOrUpdateAsync(uid, dto, token);
|
var data = await repository.AddOrUpdateAsync(uid, dto, token);
|
||||||
|
|
||||||
var idWell = telemetryService.GetIdWellByTelemetryUid(uid);
|
var idWell = telemetryService.GetIdWellByTelemetryUid(uid);
|
||||||
|
@ -328,11 +328,11 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
if (files.Count < 1)
|
if (files.Count < 1)
|
||||||
return BadRequest("Нет файла");
|
return this.ValidationBadRequest(nameof(files), "Нет файла");
|
||||||
|
|
||||||
var file = files[0];
|
var file = files[0];
|
||||||
if (Path.GetExtension(file.FileName).ToLower() != ".xlsx")
|
if (Path.GetExtension(file.FileName).ToLower() != ".xlsx")
|
||||||
return BadRequest("Требуется xlsx файл.");
|
return this.ValidationBadRequest(nameof(files), "Требуется xlsx файл.");
|
||||||
|
|
||||||
using Stream stream = file.OpenReadStream();
|
using Stream stream = file.OpenReadStream();
|
||||||
|
|
||||||
@ -348,7 +348,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
}
|
}
|
||||||
catch (FileFormatException ex)
|
catch (FileFormatException ex)
|
||||||
{
|
{
|
||||||
return BadRequest(ex.Message);
|
return this.ValidationBadRequest(nameof(files), ex.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok();
|
return Ok();
|
||||||
|
Loading…
Reference in New Issue
Block a user