using Cleanuparr.Api.Extensions; using Cleanuparr.Infrastructure.Health; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace Cleanuparr.Api.Controllers; /// /// Controller for checking the health of download clients /// [ApiController] [Route("api/health")] [Authorize] public class HealthCheckController : ControllerBase { private readonly IHealthCheckService _healthCheckService; /// /// Initializes a new instance of the class /// public HealthCheckController(IHealthCheckService healthCheckService) { _healthCheckService = healthCheckService; } /// /// Gets the health status of all download clients /// [HttpGet] public IActionResult GetAllHealth() { var healthStatuses = _healthCheckService.GetAllClientHealth(); return Ok(healthStatuses); } /// /// Gets the health status of a specific download client /// [HttpGet("{id:guid}")] public IActionResult GetClientHealth(Guid id) { var healthStatus = _healthCheckService.GetClientHealth(id); if (healthStatus == null) { return this.ProblemResult(StatusCodes.Status404NotFound, $"Health status for client with ID '{id}' not found"); } return Ok(healthStatus); } /// /// Triggers a health check for all download clients /// [HttpPost("check")] public async Task CheckAllHealth() { var results = await _healthCheckService.CheckAllClientsHealthAsync(); return Ok(results); } /// /// Triggers a health check for a specific download client /// [HttpPost("check/{id:guid}")] public async Task CheckClientHealth(Guid id) { var result = await _healthCheckService.CheckClientHealthAsync(id); return Ok(result); } }