Implemented node crud and status health check. Added daemon status health endpoint. Refactored project structure. Added sidebar items and ui views
This commit is contained in:
51
MoonlightServers.Api/Admin/Nodes/HealthController.cs
Normal file
51
MoonlightServers.Api/Admin/Nodes/HealthController.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MoonlightServers.Api.Infrastructure.Database;
|
||||
using MoonlightServers.Api.Infrastructure.Database.Entities;
|
||||
using MoonlightServers.Shared;
|
||||
using MoonlightServers.Shared.Admin.Nodes;
|
||||
|
||||
namespace MoonlightServers.Api.Admin.Nodes;
|
||||
|
||||
[ApiController]
|
||||
[Authorize(Policy = Permissions.Nodes.View)]
|
||||
[Route("api/admin/servers/nodes/{id:int}/health")]
|
||||
public class HealthController : Controller
|
||||
{
|
||||
private readonly DatabaseRepository<Node> DatabaseRepository;
|
||||
private readonly NodeService NodeService;
|
||||
private readonly ILogger<HealthController> Logger;
|
||||
|
||||
public HealthController(
|
||||
DatabaseRepository<Node> databaseRepository,
|
||||
NodeService nodeService,
|
||||
ILogger<HealthController> logger
|
||||
)
|
||||
{
|
||||
DatabaseRepository = databaseRepository;
|
||||
NodeService = nodeService;
|
||||
Logger = logger;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<NodeHealthDto>> GetAsync([FromRoute] int id)
|
||||
{
|
||||
var node = await DatabaseRepository
|
||||
.Query()
|
||||
.FirstOrDefaultAsync(x => x.Id == id);
|
||||
|
||||
if (node == null)
|
||||
return Problem("No node with this id found", statusCode: 404);
|
||||
|
||||
var health = await NodeService.GetHealthAsync(node);
|
||||
|
||||
return new NodeHealthDto()
|
||||
{
|
||||
StatusCode = health.StatusCode,
|
||||
RemoteStatusCode = health.Dto?.RemoteStatusCode ?? 0,
|
||||
IsHealthy = health is { StatusCode: >= 200 and <= 299, Dto.RemoteStatusCode: >= 200 and <= 299 }
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user