SubsystemOperationTimeController Remove validation

This commit is contained in:
ngfrolov 2023-10-10 13:49:07 +05:00
parent c5ee0eeb39
commit 95238b9e3e
Signed by untrusted user who does not match committer: ng.frolov
GPG Key ID: E99907A0357B29A7

View File

@ -1,11 +1,9 @@
using AsbCloudApp.Data;
using AsbCloudApp.Data.Subsystems;
using AsbCloudApp.Exceptions;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudApp.Services.Subsystems;
using AsbCloudDb.Model;
using AsbCloudInfrastructure;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
@ -56,7 +54,6 @@ namespace AsbCloudWebApi.Controllers.Subsystems
{
if (!await UserHasAccesToWellAsync(request.IdWell, token))
return Forbid();
await CustomValidate(request, token);
var subsystemResult = await subsystemOperationTimeService.GetStatAsync(request, token);
return Ok(subsystemResult);
}
@ -133,7 +130,6 @@ namespace AsbCloudWebApi.Controllers.Subsystems
{
if (!await UserHasAccesToWellAsync(request.IdWell, token))
return Forbid();
await CustomValidate(request, token);
var result = await subsystemOperationTimeService.GetOperationTimeAsync(request, token);
return Ok(result);
@ -155,7 +151,6 @@ namespace AsbCloudWebApi.Controllers.Subsystems
{
if (!await UserHasAccesToWellAsync(request.IdWell, token))
return Forbid();
await CustomValidate(request, token);
var result = await subsystemOperationTimeService.DeleteAsync(request, token);
return Ok(result);
}
@ -180,24 +175,5 @@ namespace AsbCloudWebApi.Controllers.Subsystems
return true;
return false;
}
/// <summary>
/// Валидирует запрос и бросает исключение ArgumentInvalidException
/// </summary>
/// <param name="request"></param>
/// <param name="token"></param>
/// <returns></returns>
/// <exception cref="ArgumentException"></exception>
private async Task CustomValidate(SubsystemOperationTimeRequest request, CancellationToken token)
{
var well = await wellService.GetOrDefaultAsync(request.IdWell, token);
if (well is not null && request.LtDate.HasValue)
{
var ltDate = request.LtDate.Value;
var utcDateRequest = ltDate.ToUtcDateTimeOffset(well.Timezone.Hours);
if (utcDateRequest.AddHours(2) > DateTime.UtcNow)
throw new ArgumentInvalidException(nameof(request.LtDate), "Запрашиваемый диапазон должен заканчиваться за 2 часа до текущего времени");
}
}
}
}