PCRB follow up client side logic

This commit is contained in:
Chase Tucker
2025-03-19 10:01:35 -07:00
parent 4871668a90
commit cc4781b990
45 changed files with 3082 additions and 1008 deletions

View File

@ -790,6 +790,42 @@ public class PCRBController : ControllerBase {
}
}
[HttpPost]
[Route("pcrb/notify/approver")]
public async Task<IActionResult> NotifyApprover(PCRBNotification notification) {
DateTime start = DateTime.Now;
bool isArgumentError = false;
bool isInternalError = false;
string errorMessage = "";
try {
_logger.LogInformation("Attempting to notify an approver");
if (notification is null) throw new ArgumentNullException("notification cannot be null");
if (notification.PCRB is null) throw new ArgumentNullException("PCRB cannot be null");
if (notification.Approval is null) throw new ArgumentNullException("approval cannot be null");
if (string.IsNullOrWhiteSpace(notification.Message)) throw new ArgumentException("message cannot be null or empty");
await _pcrbService.NotifyApprover(notification);
return Ok();
} catch (ArgumentException ex) {
isArgumentError = true;
errorMessage = ex.Message;
return BadRequest(errorMessage);
} catch (Exception ex) {
isInternalError = true;
errorMessage = $"Unable to notify an approver, because {ex.Message}";
return Problem(errorMessage);
} finally {
string metricName = "NotifyPCRBApprover";
DateTime end = DateTime.Now;
double millisecondsDiff = (end - start).TotalMilliseconds;
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
}
}
[HttpPost]
[Route("pcrb/notify/approvers")]
public async Task<IActionResult> NotifyApprovers(PCRBNotification notification) {
@ -937,7 +973,7 @@ public class PCRBController : ControllerBase {
string errorMessage = "";
try {
_logger.LogInformation($"Attempting to get attendees for plan# {planNumber}");
_logger.LogInformation($"Attempting to get follow ups for plan# {planNumber}");
if (planNumber <= 0) throw new ArgumentException($"{planNumber} is not a valid PCRB Plan#");
@ -1026,4 +1062,136 @@ public class PCRBController : ControllerBase {
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
}
}
[HttpPost]
[Route("pcrb/followUpComment")]
public async Task<IActionResult> CreateFollowUpComment(PCRBFollowUpComment comment) {
DateTime start = DateTime.Now;
bool isArgumentError = false;
bool isInternalError = false;
string errorMessage = "";
try {
_logger.LogInformation("Attempting to create follow up comment");
if (comment is null) throw new ArgumentNullException("comment cannot be null");
await _pcrbService.CreateFollowUpComment(comment);
return Ok();
} catch (ArgumentException ex) {
isArgumentError = true;
errorMessage = ex.Message;
return BadRequest(errorMessage);
} catch (Exception ex) {
isInternalError = true;
errorMessage = $"Unable to create follow up comment, because {ex.Message}";
return Problem(errorMessage);
} finally {
string metricName = "CreatePCRBFollowUpComment";
DateTime end = DateTime.Now;
double millisecondsDiff = (end - start).TotalMilliseconds;
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
}
}
[HttpGet]
[Route("pcrb/followUpComments")]
public async Task<IActionResult> GetFollowUpCommentsByPlanNumber(int planNumber, bool bypassCache) {
DateTime start = DateTime.Now;
bool isArgumentError = false;
bool isInternalError = false;
string errorMessage = "";
try {
_logger.LogInformation($"Attempting to get follow up comments for plan# {planNumber}");
if (planNumber <= 0) throw new ArgumentException($"{planNumber} is not a valid PCRB Plan#");
List<PCRBFollowUpComment> comments = (await _pcrbService.GetFollowUpCommentsByPlanNumber(planNumber, bypassCache)).ToList();
return Ok(comments);
} catch (ArgumentException ex) {
isArgumentError = true;
errorMessage = ex.Message;
return BadRequest(errorMessage);
} catch (Exception ex) {
isInternalError = true;
errorMessage = $"Cannot get follow up comments for plan# {planNumber}, because {ex.Message}";
return Problem(errorMessage);
} finally {
string metricName = "GetPCRBFollowUpComments";
DateTime end = DateTime.Now;
double millisecondsDiff = (end - start).TotalMilliseconds;
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
}
}
[HttpPut]
[Route("pcrb/followUpComment")]
public async Task<IActionResult> UpdateFollowUpComment(PCRBFollowUpComment comment) {
DateTime start = DateTime.Now;
bool isArgumentError = false;
bool isInternalError = false;
string errorMessage = "";
try {
_logger.LogInformation("Attempting to update follow up comment");
if (comment is null) throw new ArgumentNullException("comment cannot be null");
await _pcrbService.UpdateFollowUpComment(comment);
return Ok();
} catch (ArgumentException ex) {
isArgumentError = true;
errorMessage = ex.Message;
return BadRequest(errorMessage);
} catch (Exception ex) {
isInternalError = true;
errorMessage = $"Unable to update follow up comment, because {ex.Message}";
return Problem(errorMessage);
} finally {
string metricName = "UpdatePCRBFollowUpComment";
DateTime end = DateTime.Now;
double millisecondsDiff = (end - start).TotalMilliseconds;
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
}
}
[HttpDelete]
[Route("pcrb/followUpComment")]
public async Task<IActionResult> DeleteFollowUpComment(int id) {
DateTime start = DateTime.Now;
bool isArgumentError = false;
bool isInternalError = false;
string errorMessage = "";
try {
_logger.LogInformation("Attempting to delete follow up comment");
if (id <= 0) throw new ArgumentException($"{id} is not a valid PCRB follow up comment ID");
await _pcrbService.DeleteFollowUpComment(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 comment, because {ex.Message}";
return Problem(errorMessage);
} finally {
string metricName = "DeletePCRBFollowUpComment";
DateTime end = DateTime.Now;
double millisecondsDiff = (end - start).TotalMilliseconds;
_monInUtils.PostMetrics(metricName, millisecondsDiff, isArgumentError, isInternalError);
}
}
}