using HealtRegistry.Models; using HealtRegistry.Services; using Microsoft.AspNetCore.Mvc; var builder = WebApplication.CreateBuilder(args); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); builder.Services.AddSingleton(); builder.Services.AddHostedService(); builder.Services.AddOptions() .Bind(builder.Configuration) .ValidateDataAnnotations(); if (builder.Environment.IsProduction()) { builder.Configuration.AddJsonFile("/config/appsettings.json", optional: true, reloadOnChange: true); } var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(); } app.MapPost("/health/{service}", ([FromRoute] string service, IHealthService healthService) => { healthService.SetServiceHealth(service, true); return Results.Ok(); }) .WithOpenApi(); app.MapPut("/health/{service}", ([FromRoute] string service, [FromBody] HealthRequest requestBody, IHealthService healthService, [FromServices] ILoggerFactory loggerFactory) => { if (requestBody.Health.HasValue) { healthService.SetServiceHealth(service, requestBody.Health.Value); } else { var logger = loggerFactory.CreateLogger("Health"); logger.LogDebug("Health request body does not contains 'Health' property"); } return Results.Ok(); }) .WithOpenApi(); app.MapGet("/status", (IHealthService healthService) => { return healthService.GetServiceHealthes(); }) .WithOpenApi(); app.Run();