Untrusted draft — no build/test had run yet. Review before building on it. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
33 lines
1.1 KiB
C#
33 lines
1.1 KiB
C#
using ErsatzTV.Core.Api.Health;
|
|
using ErsatzTV.Core.Health;
|
|
using static ErsatzTV.Application.Health.Mapper;
|
|
|
|
namespace ErsatzTV.Application.Health;
|
|
|
|
public class GetAllHealthCheckResultsForApiHandler
|
|
: IRequestHandler<GetAllHealthCheckResultsForApi, List<HealthCheckResponseModel>>
|
|
{
|
|
private readonly IHealthCheckService _healthCheckService;
|
|
|
|
public GetAllHealthCheckResultsForApiHandler(IHealthCheckService healthCheckService) =>
|
|
_healthCheckService = healthCheckService;
|
|
|
|
public async Task<List<HealthCheckResponseModel>> Handle(
|
|
GetAllHealthCheckResultsForApi request,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
try
|
|
{
|
|
List<HealthCheckResult> results = await _healthCheckService.PerformHealthChecks(cancellationToken);
|
|
return results
|
|
.Filter(r => r.Status != HealthCheckStatus.NotApplicable)
|
|
.Map(ProjectToResponseModel)
|
|
.ToList();
|
|
}
|
|
catch (Exception ex) when (ex is TaskCanceledException or OperationCanceledException)
|
|
{
|
|
return [];
|
|
}
|
|
}
|
|
}
|