MRB webassembly
This commit is contained in:
56
MesaFabApproval.API/Controllers/CAController.cs
Normal file
56
MesaFabApproval.API/Controllers/CAController.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using MesaFabApproval.API.Services;
|
||||
using MesaFabApproval.Shared.Models;
|
||||
using MesaFabApproval.Shared.Services;
|
||||
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace MesaFabApproval.API.Controllers;
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
public class CAController : ControllerBase {
|
||||
private readonly ILogger<ApprovalController> _logger;
|
||||
private readonly ICAService _caService;
|
||||
private readonly IMonInWorkerClient _monInClient;
|
||||
|
||||
public CAController(ILogger<ApprovalController> logger, ICAService caService,
|
||||
IMonInWorkerClient monInClient) {
|
||||
_logger = logger ?? throw new ArgumentNullException("ILogger not injected");
|
||||
_caService = caService ?? throw new ArgumentNullException("ICAService not injected");
|
||||
_monInClient = monInClient ?? throw new ArgumentNullException("IMonInWorkerClient not injected");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("ca/isValidCANumber")]
|
||||
public async Task<IActionResult> IsValidCANumber(int number) {
|
||||
DateTime start = DateTime.Now;
|
||||
bool isInternalError = false;
|
||||
string errorMessage = "";
|
||||
|
||||
try {
|
||||
_logger.LogInformation($"Attempting to determine if {number} is a valid CA#");
|
||||
|
||||
if (number <= 0) return Ok(false);
|
||||
|
||||
bool isValid = await _caService.IsValidCANumber(number);
|
||||
|
||||
return Ok(isValid);
|
||||
} catch (Exception ex) {
|
||||
isInternalError = true;
|
||||
errorMessage = $"Cannot determine if {number} is a valid CA#, because {ex.Message}";
|
||||
return Problem(errorMessage);
|
||||
} finally {
|
||||
string metricName = "IsValidCANumber";
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user