diff --git a/TramsDataApi/Controllers/HealthCheckController.cs b/TramsDataApi/Controllers/HealthCheckController.cs index 1aea76981..b6ce89862 100644 --- a/TramsDataApi/Controllers/HealthCheckController.cs +++ b/TramsDataApi/Controllers/HealthCheckController.cs @@ -3,37 +3,58 @@ using Microsoft.Data.SqlClient; using Microsoft.Extensions.Logging; using TramsDataApi.DatabaseModels; +using Swashbuckle.AspNetCore.Annotations; namespace TramsDataApi.Controllers { + /// + /// Provides endpoints for checking the health of the API and database. + /// [ApiController] [Route("[controller]")] [ApiVersion("1.0")] + [SwaggerTag("Health Check Endpoints")] public class HealthCheckController : ControllerBase { private readonly LegacyTramsDbContext _dbContext; private readonly ILogger _logger; + /// + /// Constructor that initializes database and logger. + /// + /// Database context. + /// Logging service. public HealthCheckController(LegacyTramsDbContext context, ILogger logger) { _dbContext = context; _logger = logger; } - - + + /// + /// Provides a basic health check for the API. + /// + /// String message indicating health status. [HttpGet] + [SwaggerOperation(Summary = "Performs a basic health check", Description = "Checks if the API is operational.")] + [SwaggerResponse(200, "API is healthy.")] public string Get() { - _logger.LogInformation($"Returning OK Health Check"); + _logger.LogInformation("Returning OK Health Check"); return "Health check ok"; } - + + /// + /// Checks the database connectivity. + /// + /// Boolean indicating whether the database can be connected to. [HttpGet] [Route("/check_db")] + [SwaggerOperation(Summary = "Performs a database health check", Description = "Checks if the database is reachable.")] + [SwaggerResponse(200, "Database is healthy.")] public bool CheckDbConnection() { - _logger.LogInformation($"Returning Database Health Check"); + _logger.LogInformation("Returning Database Health Check"); return _dbContext.Database.CanConnect(); } } -} \ No newline at end of file +} diff --git a/TramsDataApi/Startup.cs b/TramsDataApi/Startup.cs index 0000e94ba..c5b11d28a 100644 --- a/TramsDataApi/Startup.cs +++ b/TramsDataApi/Startup.cs @@ -17,6 +17,9 @@ namespace TramsDataApi using UseCases; using TramsDataApi.SerilogCustomEnrichers; using TramsDataApi.ResponseModels; + using System.IO; + using System.Reflection; + using System; public class Startup { @@ -49,7 +52,7 @@ public void ConfigureServices(IServiceCollection services) services.AddScoped(); services.AddScoped(); services.AddScoped(); - services.AddScoped(); + services.AddScoped(); services.AddScoped(); services.AddScoped(); @@ -58,7 +61,7 @@ public void ConfigureServices(IServiceCollection services) services.AddScoped(); services.AddScoped(); - + services.AddScoped(); services.AddScoped(); @@ -73,7 +76,13 @@ public void ConfigureServices(IServiceCollection services) setup.GroupNameFormat = "'v'VVV"; setup.SubstituteApiVersionInUrl = true; }); - services.AddSwaggerGen(); + services.AddSwaggerGen(c => + { + var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; + var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); + c.IncludeXmlComments(xmlPath); + c.EnableAnnotations(); + }); services.ConfigureOptions(); services.AddUseCases(); diff --git a/TramsDataApi/TramsDataApi.csproj b/TramsDataApi/TramsDataApi.csproj index 5eac53670..991fcfe80 100644 --- a/TramsDataApi/TramsDataApi.csproj +++ b/TramsDataApi/TramsDataApi.csproj @@ -2,6 +2,7 @@ net6.0 1ce62ee2-ff0b-4f40-9066-cfbdae2e889f + true @@ -22,6 +23,7 @@ +