Expose error message using ProducesResponseType
This commit is contained in:
parent
e7b721fdb3
commit
fe3292133e
@ -3,6 +3,13 @@ namespace OI.Metrology.Shared.DataModels;
|
||||
public record WaferCounter(DateTime DateTime,
|
||||
string DateTimeFormatted,
|
||||
string EquipmentId,
|
||||
string Message,
|
||||
string Text,
|
||||
int Total,
|
||||
string SlotMap);
|
||||
string SlotMap)
|
||||
{
|
||||
|
||||
public static WaferCounter GetWaferCounter(string message) =>
|
||||
new(DateTime.MinValue, string.Empty, string.Empty, message, string.Empty, 0, string.Empty);
|
||||
|
||||
}
|
@ -4,6 +4,6 @@ public interface IWaferCounterRepository
|
||||
{
|
||||
|
||||
string? GetSlotMap(string line1, string line2);
|
||||
DataModels.WaferCounter GetLastQuantityAndSlotMap(string area, string waferSize);
|
||||
DataModels.WaferCounter? GetLastQuantityAndSlotMap(string area, string waferSize);
|
||||
|
||||
}
|
@ -12,7 +12,16 @@ public class WaferCounterController : Controller, IWaferCounterController<IActio
|
||||
public WaferCounterController(IWaferCounterRepository waferCounterRepository) =>
|
||||
_WaferCounterRepository = waferCounterRepository;
|
||||
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[HttpGet("{waferSize}/last-quantity-and-slot-map")]
|
||||
public IActionResult GetLastQuantityAndSlotMap(string area, string waferSize) =>
|
||||
Json(_WaferCounterRepository.GetLastQuantityAndSlotMap(area, waferSize));
|
||||
public IActionResult GetLastQuantityAndSlotMap(string area, string waferSize)
|
||||
{
|
||||
Shared.DataModels.WaferCounter? waferCounter = _WaferCounterRepository.GetLastQuantityAndSlotMap(area, waferSize);
|
||||
if (waferCounter is null)
|
||||
return this.BadRequest();
|
||||
else if (!string.IsNullOrEmpty(waferCounter.Message))
|
||||
return this.BadRequest(waferCounter.Message);
|
||||
else
|
||||
return Json(waferCounter);
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
using OI.Metrology.Wafer.Counter.Models;
|
||||
using OI.Metrology.Shared.DataModels;
|
||||
using OI.Metrology.Shared.Models;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using OI.Metrology.Wafer.Counter.Models;
|
||||
using System.Globalization;
|
||||
|
||||
namespace OI.Metrology.Wafer.Counter.Repository;
|
||||
@ -145,38 +145,48 @@ public class WaferCounterRepository : IWaferCounterRepository
|
||||
return results;
|
||||
}
|
||||
|
||||
private static WaferCounter GetLastQuantityAndSlotMap(string waferSize, HttpClient httpClient, NginxFileSystemSortable nginxFileSystemSortable)
|
||||
private static WaferCounter? GetLastQuantityAndSlotMap(string waferSize, HttpClient httpClient, NginxFileSystemSortable nginxFileSystemSortable)
|
||||
{
|
||||
WaferCounter result;
|
||||
string text = string.Empty;
|
||||
WaferCounter? result;
|
||||
Task<string> value = httpClient.GetStringAsync(nginxFileSystemSortable.Uri);
|
||||
value.Wait();
|
||||
string[] lines = value.Result.Split("\r\n");
|
||||
if (lines.Length <= 1)
|
||||
throw new Exception("Incomplete file length!");
|
||||
string[] segments = nginxFileSystemSortable.Name.Split('-');
|
||||
Record record = GetRecord(lines[0], lines[1]);
|
||||
string equipmentId = segments.Length <= 1 ? nginxFileSystemSortable.Name : segments[1].Split('.')[0];
|
||||
if (string.IsNullOrEmpty(record.SlotMap) || record.SlotMap.Length != 25)
|
||||
throw new Exception("Wrong length for slot-map!");
|
||||
if (record.Total != record.Check)
|
||||
throw new Exception($"Checksum has failed. {record.Total} != {record.Check}");
|
||||
result = new(nginxFileSystemSortable.DateTime, nginxFileSystemSortable.DateTime.ToString("yyyy-MM-dd hh:mm tt"), $"WC{waferSize}{equipmentId}", text, record.Total, record.SlotMap);
|
||||
if (lines.Length < 3)
|
||||
result = WaferCounter.GetWaferCounter("Incomplete file length!");
|
||||
else
|
||||
{
|
||||
string text = string.Empty;
|
||||
string[] segments = nginxFileSystemSortable.Name.Split('-');
|
||||
Record record = GetRecord(lines[^3], lines[^2]);
|
||||
string equipmentId = segments.Length <= 1 ? nginxFileSystemSortable.Name : segments[1].Split('.')[0];
|
||||
if (string.IsNullOrEmpty(record.SlotMap) || record.SlotMap.Length != 25)
|
||||
result = WaferCounter.GetWaferCounter("Wrong length for slot-map!");
|
||||
else
|
||||
{
|
||||
if (record.Total != record.Check)
|
||||
result = WaferCounter.GetWaferCounter($"Checksum has failed. {record.Total} != {record.Check}");
|
||||
else
|
||||
result = new(nginxFileSystemSortable.DateTime, nginxFileSystemSortable.DateTime.ToString("yyyy-MM-dd hh:mm tt"), $"WC{waferSize}{equipmentId}", string.Empty, text, record.Total, record.SlotMap);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
WaferCounter IWaferCounterRepository.GetLastQuantityAndSlotMap(string area, string waferSize)
|
||||
WaferCounter? IWaferCounterRepository.GetLastQuantityAndSlotMap(string area, string waferSize)
|
||||
{
|
||||
WaferCounter result;
|
||||
WaferCounter? result;
|
||||
Uri waferSizeUri = GetWaferSizeUri(area, waferSize);
|
||||
HttpClient httpClient = _HttpClientFactory.CreateClient();
|
||||
string waferSizeDirectory = GetWaferSizeDirectory(area, waferSize, destination: false);
|
||||
List<NginxFileSystemSortable> nginxFileSystemSortableCollection = GetNginxFileSystemSortableCollection(httpClient, waferSizeUri);
|
||||
if (nginxFileSystemSortableCollection.Count < 1)
|
||||
throw new Exception("No files!");
|
||||
result = GetLastQuantityAndSlotMap(waferSize, httpClient, nginxFileSystemSortableCollection[0]);
|
||||
for (int i = 0; i < nginxFileSystemSortableCollection.Count; i++)
|
||||
MoveFile(waferSizeDirectory, nginxFileSystemSortableCollection[i]);
|
||||
result = WaferCounter.GetWaferCounter("No files!");
|
||||
else
|
||||
{
|
||||
result = GetLastQuantityAndSlotMap(waferSize, httpClient, nginxFileSystemSortableCollection[0]);
|
||||
for (int i = 0; i < nginxFileSystemSortableCollection.Count; i++)
|
||||
MoveFile(waferSizeDirectory, nginxFileSystemSortableCollection[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user