using Dpz.Core.Public.ViewModel.Request;
using Dpz.Core.Public.ViewModel.Response;

namespace Dpz.Core.Service.RepositoryServiceImpl;

public class HealthCheckService(IRepository<HealthCheck> repository, IMapper mapper)
    : IHealthCheckService
{
    [Cache(ExpirationSeconds = 1 * ExpirationTime.Day)]
    public async Task<List<HealthCheckResponse>> GetHealthChecksAsync()
    {
        var list = await repository.MongodbQueryable.ToListAsync();
        return mapper.Map<List<HealthCheckResponse>>(list);
    }

    public async Task SaveHealthCheckAsync(SaveHealthCheckRequest request)
    {
        var healthCheck = mapper.Map<HealthCheck>(request);
        var exists = await repository.SearchFor(x => x.Id == healthCheck.Id).AnyAsync();
        if (exists)
        {
            await repository.UpdateAsync(healthCheck);
        }
        else
        {
            await repository.InsertAsync(healthCheck);
        }
    }

    public async Task UpdateHealthCheckStatusAsync(UpdateHealthCheckStatusRequest request)
    {
        throw new NotImplementedException();
    }

    public async Task DeleteHealthCheckAsync(string id)
    {
        await repository.DeleteAsync(id: id);
    }
}
评论加载中...