PCRB webassembly

This commit is contained in:
Chase Tucker
2024-05-13 14:33:27 -07:00
parent 9b7e3ef897
commit 89790f4fc1
50 changed files with 5466 additions and 677 deletions

View File

@ -15,10 +15,14 @@ public class MRBController : ControllerBase {
private readonly IMRBService _mrbService;
private readonly IMonInWorkerClient _monInClient;
private readonly string _mrbAttachmentPath;
public MRBController(ILogger<MRBController> logger, IMRBService mrbService, IMonInWorkerClient monInClient) {
_logger = logger ?? throw new ArgumentNullException("ILogger not injected");
_mrbService = mrbService ?? throw new ArgumentNullException("IMRBService not injected");
_monInClient = monInClient ?? throw new ArgumentNullException("IMonInWorkerClient not injected");
_mrbAttachmentPath = Environment.GetEnvironmentVariable("FabApprovalMrbAttachmentPath") ??
throw new ArgumentNullException("FabApprovalMrbAttachmentPath environment variable not found");
}
[HttpPost]
@ -692,6 +696,64 @@ public class MRBController : ControllerBase {
}
}
[AllowAnonymous]
[HttpGet]
[Route("mrb/actions/csvFile")]
public async Task<IActionResult> GetMRBActionsCsvFile(int mrbNumber) {
DateTime start = DateTime.Now;
bool isArgumentError = false;
bool isInternalError = false;
string errorMessage = "";
try {
_logger.LogInformation("Attempting to get MRB actions CSC file");
if (!(await _mrbService.MRBNumberIsValid(mrbNumber)))
throw new ArgumentException($"{mrbNumber} is not a valid MRB#");
string path = $"{_mrbAttachmentPath}\\{mrbNumber}\\mrb{mrbNumber}Actions.csv";
await _mrbService.ConvertActionsToCsvFile(mrbNumber, path);
byte[] fs = System.IO.File.ReadAllBytes(path);
const string defaultContentType = "application/octet-stream";
FileExtensionContentTypeProvider contentTypeProvider = new FileExtensionContentTypeProvider();
if (!contentTypeProvider.TryGetContentType(path, out string? contentType)) {
contentType = defaultContentType;
}
return new FileContentResult(fs, contentType) {
FileDownloadName = $"mrb{mrbNumber}Actions.csv"
};
} catch (ArgumentException ex) {
isArgumentError = true;
errorMessage = ex.Message;
return BadRequest(errorMessage);
} catch (Exception ex) {
isInternalError = true;
errorMessage = $"Cannot get MRB actions CSC file, because {ex.Message}";
return Problem(errorMessage);
} finally {
string metricName = "GetMRBActionsCSVFile";
DateTime end = DateTime.Now;
double millisecondsDiff = (end - start).TotalMilliseconds;
_monInClient.PostAverage(metricName + "Latency", millisecondsDiff);
if (isArgumentError) {
_logger.LogWarning(errorMessage);
_monInClient.PostStatus(metricName, StatusValue.Ok);
} else if (isInternalError) {
_logger.LogError(errorMessage);
_monInClient.PostStatus(metricName, StatusValue.Critical);
} else {
_monInClient.PostStatus(metricName, StatusValue.Ok);
}
}
}
[HttpDelete]
[Route("mrb/attach")]
public async Task<IActionResult> DeleteMRBAttachment(MRBAttachment attachment) {