Separated Wafer-Counter

JsonElement instead of Request body
Attachment Class
Bump
Ready to test GetLastGroupIdWithValue
Changed to v4
This commit is contained in:
2024-05-21 12:40:20 -07:00
parent 5c9f0d1aff
commit 6317c385f6
38 changed files with 1231 additions and 476 deletions

View File

@ -4,6 +4,7 @@ using OI.Metrology.Shared.Models;
using OI.Metrology.Shared.Models.Stateless;
using OI.Metrology.Shared.Services;
using System.Net;
using System.Text.Json;
namespace OI.Metrology.Server.ApiControllers;
@ -29,22 +30,9 @@ public partial class InboundController : ControllerBase, IInboundController<IAct
_MetrologyRepository = metrologyRepository;
}
private static string? GetJson(Stream stream)
{
string? result;
if (!stream.CanRead)
result = null;
else
{
Task<string> task = new StreamReader(stream).ReadToEndAsync();
result = task.Result;
}
return result;
}
[HttpPost]
[Route("{tooltype}")]
public IActionResult Post(string tooltype)
public IActionResult Post(string tooltype, JsonElement? jsonElement)
{
IPAddress? remoteIP = HttpContext.Connection.RemoteIpAddress;
if (!_InboundRepository.IsIPAddressAllowed(_AppSettings.InboundApiAllowedIPList, remoteIP))
@ -54,8 +42,7 @@ public partial class InboundController : ControllerBase, IInboundController<IAct
}
else
{
string? json = GetJson(Request.Body);
DataResponse dataResponse = _InboundRepository.Data(_MetrologyRepository, _InboundDataService, tooltype, json);
DataResponse dataResponse = _InboundRepository.Data(_MetrologyRepository, _InboundDataService, tooltype, jsonElement);
if (dataResponse.Errors.Count == 0)
return Ok(dataResponse);
else
@ -65,7 +52,7 @@ public partial class InboundController : ControllerBase, IInboundController<IAct
[HttpPost]
[Route("{tooltype}/attachment")]
public IActionResult AttachFile(string tooltype, [FromQuery] long headerid, [FromQuery] string datauniqueid = "")
public IActionResult AttachFile(string tooltype, Attachment? attachment)
{
IPAddress? remoteIP = HttpContext.Connection.RemoteIpAddress;
if (!_InboundRepository.IsIPAddressAllowed(_AppSettings.InboundApiAllowedIPList, remoteIP))
@ -75,16 +62,8 @@ public partial class InboundController : ControllerBase, IInboundController<IAct
}
else
{
if (Request.Form is null)
return BadRequest($"Invalid form");
if (Request.Form.Files.Count != 1)
return BadRequest($"Invalid file count");
IFormFile formFile = Request.Form.Files[0];
string? message = _InboundRepository.AttachFile(_MetrologyRepository, _AttachmentsService, tooltype, headerid, datauniqueid, formFile.FileName, formFile);
if (message is null)
return Ok();
else
return BadRequest(message);
_InboundRepository.AttachFile(_MetrologyRepository, _AttachmentsService, tooltype, attachment);
return Ok();
}
}