PCRB follow up endpoints
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
using MesaFabApproval.API.Services;
|
||||
using MesaFabApproval.API.Utilities;
|
||||
using MesaFabApproval.Shared.Models;
|
||||
using MesaFabApproval.Shared.Services;
|
||||
|
||||
@ -13,12 +14,12 @@ namespace MesaFabApproval.API.Controllers;
|
||||
public class PCRBController : ControllerBase {
|
||||
private readonly ILogger<MRBController> _logger;
|
||||
private readonly IPCRBService _pcrbService;
|
||||
private readonly IMonInWorkerClient _monInClient;
|
||||
private readonly IMonInUtils _monInUtils;
|
||||
|
||||
public PCRBController(ILogger<MRBController> logger, IPCRBService pcrbService, IMonInWorkerClient monInClient) {
|
||||
public PCRBController(ILogger<MRBController> logger, IPCRBService pcrbService, IMonInUtils monInUtils) {
|
||||
_logger = logger ?? throw new ArgumentNullException("ILogger not injected");
|
||||
_pcrbService = pcrbService ?? throw new ArgumentNullException("IPCRBService not injected");
|
||||
_monInClient = monInClient ?? throw new ArgumentNullException("IMonInWorkerClient not injected");
|
||||
_monInUtils = monInUtils ?? throw new ArgumentNullException("IMonInUtils not injected");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
@ -49,17 +50,8 @@ public class PCRBController : ControllerBase {
|
||||
string metricName = "CreateNewPCRB";
|
||||
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);
|
||||
}
|
||||
|
||||
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,14 +76,8 @@ public class PCRBController : ControllerBase {
|
||||
string metricName = "GetAllPCRBs";
|
||||
DateTime end = DateTime.Now;
|
||||
double millisecondsDiff = (end - start).TotalMilliseconds;
|
||||
_monInClient.PostAverage(metricName + "Latency", millisecondsDiff);
|
||||
|
||||
if (isInternalError) {
|
||||
_logger.LogError(errorMessage);
|
||||
_monInClient.PostStatus(metricName, StatusValue.Critical);
|
||||
} else {
|
||||
_monInClient.PostStatus(metricName, StatusValue.Ok);
|
||||
}
|
||||
|
||||
_monInUtils.PostMetrics(metricName, millisecondsDiff, false, isInternalError);
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,17 +109,8 @@ public class PCRBController : ControllerBase {
|
||||
string metricName = "GetPCRBbyTitle";
|
||||
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);
|
||||
}
|
||||
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
|
||||
}
|
||||
}
|
||||
|
||||
@ -165,17 +142,8 @@ public class PCRBController : ControllerBase {
|
||||
string metricName = "GetPCRBbyPlanNumber";
|
||||
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);
|
||||
}
|
||||
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
|
||||
}
|
||||
}
|
||||
|
||||
@ -207,17 +175,8 @@ public class PCRBController : ControllerBase {
|
||||
string metricName = "UpdatePCRB";
|
||||
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);
|
||||
}
|
||||
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
|
||||
}
|
||||
}
|
||||
|
||||
@ -249,17 +208,8 @@ public class PCRBController : ControllerBase {
|
||||
string metricName = "DeletePCRB";
|
||||
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);
|
||||
}
|
||||
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
|
||||
}
|
||||
}
|
||||
|
||||
@ -294,17 +244,8 @@ public class PCRBController : ControllerBase {
|
||||
string metricName = "UploadPCRBAttachment";
|
||||
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);
|
||||
}
|
||||
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
|
||||
}
|
||||
}
|
||||
|
||||
@ -336,17 +277,8 @@ public class PCRBController : ControllerBase {
|
||||
string metricName = "GetPCRBAttachments";
|
||||
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);
|
||||
}
|
||||
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
|
||||
}
|
||||
}
|
||||
|
||||
@ -391,17 +323,8 @@ public class PCRBController : ControllerBase {
|
||||
string metricName = "GetPCRBAttachmentFile";
|
||||
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);
|
||||
}
|
||||
|
||||
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
|
||||
}
|
||||
}
|
||||
|
||||
@ -433,17 +356,8 @@ public class PCRBController : ControllerBase {
|
||||
string metricName = "UpdatePCRBAttachment";
|
||||
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);
|
||||
}
|
||||
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
|
||||
}
|
||||
}
|
||||
|
||||
@ -475,17 +389,8 @@ public class PCRBController : ControllerBase {
|
||||
string metricName = "DeletePCRBAttachment";
|
||||
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);
|
||||
}
|
||||
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
|
||||
}
|
||||
}
|
||||
|
||||
@ -517,17 +422,8 @@ public class PCRBController : ControllerBase {
|
||||
string metricName = "CreatePCRBActionItem";
|
||||
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);
|
||||
}
|
||||
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
|
||||
}
|
||||
}
|
||||
|
||||
@ -559,17 +455,8 @@ public class PCRBController : ControllerBase {
|
||||
string metricName = "UpdatePCRBActionItem";
|
||||
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);
|
||||
}
|
||||
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
|
||||
}
|
||||
}
|
||||
|
||||
@ -601,17 +488,8 @@ public class PCRBController : ControllerBase {
|
||||
string metricName = "DeletePCRBActionItem";
|
||||
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);
|
||||
}
|
||||
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
|
||||
}
|
||||
}
|
||||
|
||||
@ -643,17 +521,8 @@ public class PCRBController : ControllerBase {
|
||||
string metricName = "GetPCRBActionItems";
|
||||
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);
|
||||
}
|
||||
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
|
||||
}
|
||||
}
|
||||
|
||||
@ -685,17 +554,8 @@ public class PCRBController : ControllerBase {
|
||||
string metricName = "CreatePCR3Document";
|
||||
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);
|
||||
}
|
||||
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
|
||||
}
|
||||
}
|
||||
|
||||
@ -727,17 +587,8 @@ public class PCRBController : ControllerBase {
|
||||
string metricName = "UpdatePCR3Document";
|
||||
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);
|
||||
}
|
||||
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
|
||||
}
|
||||
}
|
||||
|
||||
@ -769,17 +620,8 @@ public class PCRBController : ControllerBase {
|
||||
string metricName = "GetPCR3Documents";
|
||||
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);
|
||||
}
|
||||
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
|
||||
}
|
||||
}
|
||||
|
||||
@ -811,17 +653,8 @@ public class PCRBController : ControllerBase {
|
||||
string metricName = "CreatePCRBAttendee";
|
||||
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);
|
||||
}
|
||||
|
||||
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
|
||||
}
|
||||
}
|
||||
|
||||
@ -853,17 +686,8 @@ public class PCRBController : ControllerBase {
|
||||
string metricName = "UpdatePCRBAttendee";
|
||||
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);
|
||||
}
|
||||
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
|
||||
}
|
||||
}
|
||||
|
||||
@ -895,17 +719,8 @@ public class PCRBController : ControllerBase {
|
||||
string metricName = "DeletePCRBAttendee";
|
||||
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);
|
||||
}
|
||||
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
|
||||
}
|
||||
}
|
||||
|
||||
@ -937,17 +752,8 @@ public class PCRBController : ControllerBase {
|
||||
string metricName = "GetPCRBAttendees";
|
||||
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);
|
||||
}
|
||||
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
|
||||
}
|
||||
}
|
||||
|
||||
@ -979,17 +785,8 @@ public class PCRBController : ControllerBase {
|
||||
string metricName = "NotifyNewPCRBApprovers";
|
||||
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);
|
||||
}
|
||||
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1023,17 +820,8 @@ public class PCRBController : ControllerBase {
|
||||
string metricName = "NotifyPCRBApprovers";
|
||||
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);
|
||||
}
|
||||
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1067,17 +855,8 @@ public class PCRBController : ControllerBase {
|
||||
string metricName = "NotifyPCRBOriginator";
|
||||
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);
|
||||
}
|
||||
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1111,17 +890,140 @@ public class PCRBController : ControllerBase {
|
||||
string metricName = "NotifyPCRBResponsiblePerson";
|
||||
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);
|
||||
}
|
||||
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("pcrb/followUp")]
|
||||
public async Task<IActionResult> CreateFollowUp(PCRBFollowUp followUp) {
|
||||
DateTime start = DateTime.Now;
|
||||
bool isArgumentError = false;
|
||||
bool isInternalError = false;
|
||||
string errorMessage = "";
|
||||
|
||||
try {
|
||||
_logger.LogInformation("Attempting to create follow up");
|
||||
|
||||
if (followUp is null) throw new ArgumentNullException("follow up cannot be null");
|
||||
|
||||
await _pcrbService.CreateFollowUp(followUp);
|
||||
|
||||
return Ok();
|
||||
} catch (ArgumentException ex) {
|
||||
isArgumentError = true;
|
||||
errorMessage = ex.Message;
|
||||
return BadRequest(errorMessage);
|
||||
} catch (Exception ex) {
|
||||
isInternalError = true;
|
||||
errorMessage = $"Unable to create follow up, because {ex.Message}";
|
||||
return Problem(errorMessage);
|
||||
} finally {
|
||||
string metricName = "CreatePCRBFollowUp";
|
||||
DateTime end = DateTime.Now;
|
||||
double millisecondsDiff = (end - start).TotalMilliseconds;
|
||||
|
||||
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("pcrb/followUps")]
|
||||
public async Task<IActionResult> GetFollowUpsByPlanNumber(int planNumber, bool bypassCache) {
|
||||
DateTime start = DateTime.Now;
|
||||
bool isArgumentError = false;
|
||||
bool isInternalError = false;
|
||||
string errorMessage = "";
|
||||
|
||||
try {
|
||||
_logger.LogInformation($"Attempting to get attendees for plan# {planNumber}");
|
||||
|
||||
if (planNumber <= 0) throw new ArgumentException($"{planNumber} is not a valid PCRB Plan#");
|
||||
|
||||
List<PCRBFollowUp> attendees = (await _pcrbService.GetFollowUpsByPlanNumber(planNumber, bypassCache)).ToList();
|
||||
|
||||
return Ok(attendees);
|
||||
} catch (ArgumentException ex) {
|
||||
isArgumentError = true;
|
||||
errorMessage = ex.Message;
|
||||
return BadRequest(errorMessage);
|
||||
} catch (Exception ex) {
|
||||
isInternalError = true;
|
||||
errorMessage = $"Cannot get follow ups for plan# {planNumber}, because {ex.Message}";
|
||||
return Problem(errorMessage);
|
||||
} finally {
|
||||
string metricName = "GetPCRBFollowUps";
|
||||
DateTime end = DateTime.Now;
|
||||
double millisecondsDiff = (end - start).TotalMilliseconds;
|
||||
|
||||
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
[Route("pcrb/followUp")]
|
||||
public async Task<IActionResult> UpdateFollowUp(PCRBFollowUp followUp) {
|
||||
DateTime start = DateTime.Now;
|
||||
bool isArgumentError = false;
|
||||
bool isInternalError = false;
|
||||
string errorMessage = "";
|
||||
|
||||
try {
|
||||
_logger.LogInformation("Attempting to update follow up");
|
||||
|
||||
if (followUp is null) throw new ArgumentNullException("follow up cannot be null");
|
||||
|
||||
await _pcrbService.UpdateFollowUp(followUp);
|
||||
|
||||
return Ok();
|
||||
} catch (ArgumentException ex) {
|
||||
isArgumentError = true;
|
||||
errorMessage = ex.Message;
|
||||
return BadRequest(errorMessage);
|
||||
} catch (Exception ex) {
|
||||
isInternalError = true;
|
||||
errorMessage = $"Unable to update follow up, because {ex.Message}";
|
||||
return Problem(errorMessage);
|
||||
} finally {
|
||||
string metricName = "UpdatePCRBFollowUp";
|
||||
DateTime end = DateTime.Now;
|
||||
double millisecondsDiff = (end - start).TotalMilliseconds;
|
||||
|
||||
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
[Route("pcrb/followUp")]
|
||||
public async Task<IActionResult> DeleteFollowUp(int id) {
|
||||
DateTime start = DateTime.Now;
|
||||
bool isArgumentError = false;
|
||||
bool isInternalError = false;
|
||||
string errorMessage = "";
|
||||
|
||||
try {
|
||||
_logger.LogInformation("Attempting to delete follow up");
|
||||
|
||||
if (id <= 0) throw new ArgumentException($"{id} is not a valid PCRB follow up ID");
|
||||
|
||||
await _pcrbService.DeleteFollowUp(id);
|
||||
|
||||
return Ok();
|
||||
} catch (ArgumentException ex) {
|
||||
isArgumentError = true;
|
||||
errorMessage = ex.Message;
|
||||
return BadRequest(errorMessage);
|
||||
} catch (Exception ex) {
|
||||
isInternalError = true;
|
||||
errorMessage = $"Unable to delete follow up, because {ex.Message}";
|
||||
return Problem(errorMessage);
|
||||
} finally {
|
||||
string metricName = "DeletePCRBFollowUp";
|
||||
DateTime end = DateTime.Now;
|
||||
double millisecondsDiff = (end - start).TotalMilliseconds;
|
||||
|
||||
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
|
||||
}
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ using dotenv.net;
|
||||
|
||||
using MesaFabApproval.API.Clients;
|
||||
using MesaFabApproval.API.Services;
|
||||
using MesaFabApproval.API.Utilities;
|
||||
using MesaFabApproval.Models;
|
||||
using MesaFabApproval.Shared.Services;
|
||||
|
||||
@ -94,6 +95,7 @@ builder.Services.AddScoped<IECNService, ECNService>();
|
||||
builder.Services.AddScoped<ISmtpService, SmtpService>();
|
||||
builder.Services.AddScoped<IUserService, UserService>();
|
||||
builder.Services.AddScoped<IMonInWorkerClient, MonInWorkerClient>();
|
||||
builder.Services.AddScoped<IMonInUtils, MonInUtils>();
|
||||
builder.Services.AddScoped<IAuthenticationService, AuthenticationService>();
|
||||
builder.Services.AddScoped<IMRBService, MRBService>();
|
||||
builder.Services.AddScoped<IPCRBService, PCRBService>();
|
||||
@ -101,7 +103,6 @@ builder.Services.AddScoped<IApprovalService, ApprovalService>();
|
||||
|
||||
builder.Services.AddControllers();
|
||||
|
||||
#if DEBUG
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen(c => {
|
||||
c.SwaggerDoc("v1", new OpenApiInfo {
|
||||
@ -128,7 +129,6 @@ builder.Services.AddSwaggerGen(c => {
|
||||
}
|
||||
});
|
||||
});
|
||||
#endif
|
||||
|
||||
WebApplication app = builder.Build();
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Data;
|
||||
using System.Text;
|
||||
|
||||
using Dapper;
|
||||
|
||||
@ -6,7 +7,9 @@ namespace MesaFabApproval.API.Services;
|
||||
|
||||
public interface IDalService {
|
||||
Task<IEnumerable<T>> QueryAsync<T>(string sql);
|
||||
Task<IEnumerable<T>> QueryAsync<T>(string sql, object paramaters);
|
||||
Task<int> ExecuteAsync(string sql);
|
||||
Task<int> ExecuteAsync<T>(string sql, T paramaters);
|
||||
}
|
||||
|
||||
public class DalService : IDalService {
|
||||
@ -55,6 +58,45 @@ public class DalService : IDalService {
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<T>> QueryAsync<T>(string sql, object parameters) {
|
||||
if (sql is null) throw new ArgumentNullException("sql cannot be null");
|
||||
if (parameters is null) throw new ArgumentNullException("parameters cannot be null");
|
||||
|
||||
StringBuilder logBuilder = new();
|
||||
|
||||
int remainingRetries = RETRIES;
|
||||
bool queryWasSuccessful = false;
|
||||
Exception exception = null;
|
||||
IEnumerable<T> result = new List<T>();
|
||||
while (!queryWasSuccessful && remainingRetries > 0) {
|
||||
int backoffSeconds = (RETRIES - remainingRetries--) * BACKOFF_SECONDS_INTERVAL;
|
||||
Task.Delay(backoffSeconds * 1000).Wait();
|
||||
|
||||
try {
|
||||
logBuilder.Clear();
|
||||
logBuilder.Append($"Attempting to perform query with {sql} ");
|
||||
logBuilder.Append($"and parameters {parameters.ToString()}. ");
|
||||
logBuilder.Append($"Remaining retries: {remainingRetries}");
|
||||
_logger.LogInformation(logBuilder.ToString());
|
||||
|
||||
using (IDbConnection conn = _dbConnectionService.GetConnection()) {
|
||||
result = await conn.QueryAsync<T>(sql, parameters);
|
||||
}
|
||||
|
||||
queryWasSuccessful = true;
|
||||
} catch (Exception ex) {
|
||||
_logger.LogError($"An exception occurred while attempting to perform a query. Exception: {ex.Message}");
|
||||
exception = ex;
|
||||
}
|
||||
}
|
||||
|
||||
if (!queryWasSuccessful && exception is not null) {
|
||||
throw exception;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<int> ExecuteAsync(string sql) {
|
||||
if (sql is null) throw new ArgumentNullException("sql cannot be null");
|
||||
|
||||
@ -86,4 +128,36 @@ public class DalService : IDalService {
|
||||
|
||||
return rowsAffected;
|
||||
}
|
||||
|
||||
public async Task<int> ExecuteAsync<T>(string sql, T parameters) {
|
||||
if (sql is null) throw new ArgumentNullException("sql cannot be null");
|
||||
|
||||
int remainingRetries = RETRIES;
|
||||
bool queryWasSuccessful = false;
|
||||
Exception exception = null;
|
||||
int rowsAffected = 0;
|
||||
while (!queryWasSuccessful && remainingRetries > 0) {
|
||||
int backoffSeconds = (RETRIES - remainingRetries--) * BACKOFF_SECONDS_INTERVAL;
|
||||
Task.Delay(backoffSeconds * 1000).Wait();
|
||||
|
||||
try {
|
||||
_logger.LogInformation($"Attempting to execute {sql} with parameters. Remaining retries: {remainingRetries}");
|
||||
|
||||
using (IDbConnection conn = _dbConnectionService.GetConnection()) {
|
||||
rowsAffected = await conn.ExecuteAsync(sql, parameters);
|
||||
}
|
||||
|
||||
queryWasSuccessful = true;
|
||||
} catch (Exception ex) {
|
||||
_logger.LogError($"An exception occurred while attempting to execute a query. Exception: {ex.Message}");
|
||||
exception = ex;
|
||||
}
|
||||
}
|
||||
|
||||
if (!queryWasSuccessful && exception is not null) {
|
||||
throw exception;
|
||||
}
|
||||
|
||||
return rowsAffected;
|
||||
}
|
||||
}
|
@ -37,6 +37,10 @@ public interface IPCRBService {
|
||||
Task NotifyApprovers(PCRBNotification notification);
|
||||
Task NotifyOriginator(PCRBNotification notification);
|
||||
Task NotifyResponsiblePerson(PCRBActionItemNotification notification);
|
||||
Task CreateFollowUp(PCRBFollowUp followUp);
|
||||
Task<IEnumerable<PCRBFollowUp>> GetFollowUpsByPlanNumber(int planNumber, bool bypassCache);
|
||||
Task UpdateFollowUp(PCRBFollowUp followUp);
|
||||
Task DeleteFollowUp(int id);
|
||||
}
|
||||
|
||||
public class PCRBService : IPCRBService {
|
||||
@ -755,6 +759,90 @@ public class PCRBService : IPCRBService {
|
||||
}
|
||||
}
|
||||
|
||||
public async Task CreateFollowUp(PCRBFollowUp followUp) {
|
||||
try {
|
||||
_logger.LogInformation("Attempting to create PCRB follow up");
|
||||
|
||||
if (followUp is null) throw new ArgumentNullException("follow up cannot be null");
|
||||
|
||||
StringBuilder queryBuilder = new();
|
||||
queryBuilder.Append("insert into CCPCRBFollowUp (PlanNumber, Step, FollowUpDate, CompletedDate) ");
|
||||
queryBuilder.Append("values (@PlanNumber, @Step, @FollowUpDate, @CompletedDate)");
|
||||
|
||||
int rowsReturned = await _dalService.ExecuteAsync<PCRBFollowUp>(queryBuilder.ToString(), followUp);
|
||||
|
||||
if (rowsReturned <= 0) throw new Exception("unable to insert new follow up in the database");
|
||||
} catch (Exception ex) {
|
||||
_logger.LogError($"Unable to create new follow up, because {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<PCRBFollowUp>> GetFollowUpsByPlanNumber(int planNumber, bool bypassCache) {
|
||||
try {
|
||||
_logger.LogInformation($"Attempting to fetch follow ups for PCRB {planNumber}");
|
||||
|
||||
if (planNumber <= 0) throw new ArgumentException($"{planNumber} is not a valid PCRB Plan#");
|
||||
|
||||
IEnumerable<PCRBFollowUp>? followUps = new List<PCRBFollowUp>();
|
||||
|
||||
if (!bypassCache)
|
||||
followUps = _cache.Get<IEnumerable<PCRBFollowUp>>($"pcrbFollowUps{planNumber}");
|
||||
|
||||
if (followUps is null || followUps.Count() == 0) {
|
||||
string sql = "select * from CCPCRBFollowUp where PlanNumber=@PlanNumber";
|
||||
|
||||
followUps = await _dalService.QueryAsync<PCRBFollowUp>(sql, new { PlanNumber = planNumber });
|
||||
|
||||
if (followUps is not null)
|
||||
_cache.Set($"pcrbFollowUps{planNumber}", followUps, DateTimeOffset.Now.AddMinutes(15));
|
||||
}
|
||||
|
||||
return followUps ?? new List<PCRBFollowUp>();
|
||||
} catch (Exception ex) {
|
||||
_logger.LogError($"Unable to fetch follow ups for PCRB {planNumber}, because {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task UpdateFollowUp(PCRBFollowUp followUp) {
|
||||
try {
|
||||
_logger.LogInformation("Attempting to update a follow up");
|
||||
|
||||
if (followUp is null)
|
||||
throw new ArgumentNullException("follow up cannot be null");
|
||||
|
||||
StringBuilder queryBuilder = new();
|
||||
queryBuilder.Append("update CCPCRBFollowUp set Step=@Step, FollowUpDate=@FollowUpDate, IsComplete=@IsComplete, ");
|
||||
queryBuilder.Append("IsDeleted=@IsDeleted, CompletedDate=@CompletedDate, Comments=@Comments ");
|
||||
queryBuilder.Append("where ID=@ID");
|
||||
|
||||
int rowsAffected = await _dalService.ExecuteAsync<PCRBFollowUp>(queryBuilder.ToString(), followUp);
|
||||
|
||||
if (rowsAffected <= 0) throw new Exception("update failed in database");
|
||||
} catch (Exception ex) {
|
||||
_logger.LogError($"Unable to update follow up, because {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteFollowUp(int id) {
|
||||
try {
|
||||
_logger.LogInformation($"Attempting to delete follow up {id}");
|
||||
|
||||
if (id <= 0) throw new ArgumentException($"{id} is not a valid follow up ID");
|
||||
|
||||
string sql = "delete from CCPCRBFollowUp where ID=@ID";
|
||||
|
||||
int rowsAffected = await _dalService.ExecuteAsync(sql, new { ID = id });
|
||||
|
||||
if (rowsAffected <= 0) throw new Exception("delete operation failed in database");
|
||||
} catch (Exception ex) {
|
||||
_logger.LogError($"Unable to delete follow up {id}, because {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SaveAttachmentInDb(IFormFile file, PCRBAttachment attachment) {
|
||||
try {
|
||||
_logger.LogInformation($"Attempting to save attachment to database");
|
||||
|
48
MesaFabApproval.API/Utilities/MonInUtils.cs
Normal file
48
MesaFabApproval.API/Utilities/MonInUtils.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using MesaFabApproval;
|
||||
using MesaFabApproval.API;
|
||||
using MesaFabApproval.API.Services;
|
||||
using MesaFabApproval.API.Utilities;
|
||||
using MesaFabApproval.Shared.Models;
|
||||
using MesaFabApproval.Shared.Services;
|
||||
|
||||
namespace MesaFabApproval.API.Utilities;
|
||||
|
||||
public interface IMonInUtils {
|
||||
public void PostMetrics(string metricName,
|
||||
double latency,
|
||||
bool isArgumentError,
|
||||
bool isInternalError);
|
||||
}
|
||||
|
||||
public class MonInUtils : IMonInUtils {
|
||||
private readonly IMonInWorkerClient _monInClient;
|
||||
private readonly ILogger<MonInUtils> _logger;
|
||||
|
||||
public MonInUtils(IMonInWorkerClient monInClient, ILogger<MonInUtils> logger) {
|
||||
_monInClient = monInClient ??
|
||||
throw new ArgumentNullException("IMonInWorkerClient not injected");
|
||||
_logger = logger ??
|
||||
throw new ArgumentNullException("ILogger not injected");
|
||||
}
|
||||
|
||||
public void PostMetrics(string metricName,
|
||||
double latency,
|
||||
bool isArgumentError,
|
||||
bool isInternalError) {
|
||||
try {
|
||||
_logger.LogInformation("Attempting to post metrics to MonIn");
|
||||
|
||||
_monInClient.PostAverage(metricName + "Latency", latency);
|
||||
|
||||
if (isArgumentError) {
|
||||
_monInClient.PostStatus(metricName, StatusValue.Ok);
|
||||
} else if (isInternalError) {
|
||||
_monInClient.PostStatus(metricName, StatusValue.Critical);
|
||||
} else {
|
||||
_monInClient.PostStatus(metricName, StatusValue.Ok);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
_logger.LogError($"Unable to post metrics to MonIn, because {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
@ -30,6 +30,14 @@ stages:
|
||||
configuration: $(BuildConfiguration)
|
||||
projects: MesaFabApproval.API
|
||||
|
||||
- task: DotNetCoreCLI@2
|
||||
displayName: "Test"
|
||||
inputs:
|
||||
command: "test"
|
||||
configuration: $(BuildConfiguration)
|
||||
publishTestResults: true
|
||||
projects: MesaFabApproval.API.Test
|
||||
|
||||
- task: DotNetCoreCLI@2
|
||||
displayName: "Publish"
|
||||
inputs:
|
||||
@ -66,6 +74,14 @@ stages:
|
||||
configuration: $(BuildConfiguration)
|
||||
projects: MesaFabApproval.API
|
||||
|
||||
- task: DotNetCoreCLI@2
|
||||
displayName: "Test"
|
||||
inputs:
|
||||
command: "test"
|
||||
configuration: $(BuildConfiguration)
|
||||
publishTestResults: true
|
||||
projects: MesaFabApproval.API.Test
|
||||
|
||||
- task: DotNetCoreCLI@2
|
||||
displayName: "Publish"
|
||||
inputs:
|
||||
|
Reference in New Issue
Block a user