Removed FromBody

This commit is contained in:
2023-03-08 10:04:15 -07:00
parent db44756142
commit de048b6842
7 changed files with 155 additions and 35 deletions

View File

@ -15,25 +15,60 @@ public class ExportController : Controller, IExportController<IActionResult>
public ExportController(IExportRepository exportRepository) =>
_ExportRepository = exportRepository;
private static HeaderCommon GetHeaderCommon(Stream stream)
{
HeaderCommon? result;
if (!stream.CanRead)
result = new();
else
{
Task<string> task = new StreamReader(stream).ReadToEndAsync();
result = string.IsNullOrEmpty(task.Result) ? null : JsonSerializer.Deserialize<HeaderCommon>(task.Result);
result ??= new();
}
return result;
}
[HttpGet]
[Route("export")]
public IActionResult GetExport(HeaderCommon headerCommon) =>
Content(_ExportRepository.GetExport(headerCommon));
public IActionResult GetExport() =>
Content(_ExportRepository.GetExport(GetHeaderCommon(Request.Body)));
[HttpGet]
[Route("headers")]
public IActionResult GetHeaders(HeaderCommon headerCommon) =>
Json(_ExportRepository.GetHeaders(headerCommon), new JsonSerializerOptions { PropertyNamingPolicy = null, WriteIndented = true });
public IActionResult GetHeaders() =>
Json(_ExportRepository.GetHeaders(GetHeaderCommon(Request.Body)), new JsonSerializerOptions { PropertyNamingPolicy = null, WriteIndented = true });
[HttpGet]
[Route("logistics")]
public IActionResult GetLogistics(HeaderCommon headerCommon) =>
Json(_ExportRepository.GetLogistics(headerCommon), new JsonSerializerOptions { PropertyNamingPolicy = null, WriteIndented = true });
public IActionResult GetLogistics() =>
Json(_ExportRepository.GetLogistics(GetHeaderCommon(Request.Body)), new JsonSerializerOptions { PropertyNamingPolicy = null, WriteIndented = true });
[HttpGet]
[Route("pdsf")]
[Route("processDataStandardFormat")]
public IActionResult GetProcessDataStandardFormat(HeaderCommon headerCommon) =>
Content(_ExportRepository.GetProcessDataStandardFormat(headerCommon));
public IActionResult GetProcessDataStandardFormat() =>
Content(_ExportRepository.GetProcessDataStandardFormat(GetHeaderCommon(Request.Body)));
[HttpPost]
[Route("export")]
public IActionResult PostExport() =>
Content(_ExportRepository.GetExport(GetHeaderCommon(Request.Body)));
[HttpPost]
[Route("headers")]
public IActionResult PostHeaders() =>
Json(_ExportRepository.GetHeaders(GetHeaderCommon(Request.Body)), new JsonSerializerOptions { PropertyNamingPolicy = null, WriteIndented = true });
[HttpPost]
[Route("logistics")]
public IActionResult PostLogistics() =>
Json(_ExportRepository.GetLogistics(GetHeaderCommon(Request.Body)), new JsonSerializerOptions { PropertyNamingPolicy = null, WriteIndented = true });
[HttpPost]
[Route("pdsf")]
[Route("processDataStandardFormat")]
public IActionResult PostProcessDataStandardFormat() =>
Content(_ExportRepository.GetProcessDataStandardFormat(GetHeaderCommon(Request.Body)));
}

View File

@ -30,9 +30,24 @@ public partial class InboundController : ControllerBase, IInboundController<IAct
_MetrologyRepository = metrologyRepository;
}
private static JToken GetJToken(Stream stream)
{
JToken jsonbody;
if (!stream.CanRead)
jsonbody = JToken.Parse("{}");
else
{
if (stream.CanSeek)
_ = stream.Seek(0, SeekOrigin.Begin);
string json = new StreamReader(stream).ReadToEnd();
jsonbody = JToken.Parse(json);
}
return jsonbody;
}
[HttpPost]
[Route("{tooltype}")]
public IActionResult Post(string tooltype, [FromBody] JToken jsonbody)
public IActionResult Post(string tooltype)
{
IPAddress? remoteIP = HttpContext.Connection.RemoteIpAddress;
if (!_InboundRepository.IsIPAddressAllowed(_AppSettings.InboundApiAllowedIPList, remoteIP))
@ -42,18 +57,7 @@ public partial class InboundController : ControllerBase, IInboundController<IAct
}
else
{
if (jsonbody is null || !jsonbody.Any())
{
if (!Request.Body.CanRead)
jsonbody = JToken.Parse("{}");
else
{
using Stream stream = Request.Body;
_ = stream.Seek(0, SeekOrigin.Begin);
string json = new StreamReader(stream).ReadToEnd();
jsonbody = JToken.Parse(json);
}
}
JToken jsonbody = GetJToken(Request.Body);
DataResponse dataResponse = _InboundRepository.Data(_MetrologyRepository, _InboundDataService, tooltype, jsonbody);
if (!dataResponse.Errors.Any())
return Ok(dataResponse);

View File

@ -96,7 +96,6 @@ public class ExportRepository : IExportRepository
};
}
return result;
}
Result<HeaderCommon[]> IExportRepository.GetLogistics(HeaderCommon headerCommon)