diff --git a/src/SwiftLink.Application/Constants/Constants.cs b/src/SwiftLink.Application/Constants/Constants.cs index e65a706..1d016c2 100644 --- a/src/SwiftLink.Application/Constants/Constants.cs +++ b/src/SwiftLink.Application/Constants/Constants.cs @@ -2,6 +2,12 @@ internal static class Constants { + public static class Database + { + public static string InsertFailed = "Insert into db is failed :("; + + } + public static class Link { public static string UrlMustBeSent = "Url must be sent!"; diff --git a/src/SwiftLink.Application/UseCases/Links/GenerateCommand/GenerateShortCodeCommandHandler.cs b/src/SwiftLink.Application/UseCases/Links/GenerateCommand/GenerateShortCodeCommandHandler.cs index 392b9ae..5282410 100644 --- a/src/SwiftLink.Application/UseCases/Links/GenerateCommand/GenerateShortCodeCommandHandler.cs +++ b/src/SwiftLink.Application/UseCases/Links/GenerateCommand/GenerateShortCodeCommandHandler.cs @@ -33,7 +33,7 @@ public async Task> Handle(GenerateShortCodeCommand request, Cance var dbResult = await _dbContext.SaveChangesAsync(cancellationToken); if (dbResult.IsFailure) - return Result.Failure(); + return Result.Failure(Constants.Database.InsertFailed); await _cache.Set(request.Url, JsonSerializer.Serialize(link), link.ExpirationDate); return Result.Success(link); diff --git a/src/SwiftLink.Presentation/Program.cs b/src/SwiftLink.Presentation/Program.cs index dff929b..810fbc3 100644 --- a/src/SwiftLink.Presentation/Program.cs +++ b/src/SwiftLink.Presentation/Program.cs @@ -4,6 +4,9 @@ using SwiftLink.Infrastructure; using SwiftLink.Presentation; using SwiftLink.Shared; +using HealthChecks; +using SwiftLink.Infrastructure.Persistence.Context; +using Microsoft.AspNetCore.Diagnostics.HealthChecks; var builder = WebApplication.CreateBuilder(args); { @@ -31,11 +34,16 @@ options.SubstituteApiVersionInUrl = true; }); builder.Services.AddHealthChecks(); + + builder.Services + .AddHealthChecks() + + .AddSqlServer(builder.Configuration.GetConnectionString(nameof(ApplicationDbContext))); + // .AddRedis(builder.Configuration["AppSettings:RedisCacheUrl"]); } var app = builder.Build(); { - app.MapHealthChecks("/health"); app.UseExceptionHandler(error => { error.Run(async context => @@ -51,5 +59,14 @@ app.UseHttpsRedirection(); app.UseAuthorization(); app.MapControllers(); + app.UseRouting() + .UseEndpoints(config => + { + config.MapHealthChecks("/health", new HealthCheckOptions + { + Predicate = _ => true + //ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse + }); + }); app.Run(); } \ No newline at end of file diff --git a/src/SwiftLink.Presentation/SwiftLink.Presentation.csproj b/src/SwiftLink.Presentation/SwiftLink.Presentation.csproj index 6f0ab6a..7f807d7 100644 --- a/src/SwiftLink.Presentation/SwiftLink.Presentation.csproj +++ b/src/SwiftLink.Presentation/SwiftLink.Presentation.csproj @@ -2,7 +2,7 @@ net8.0 - enable + disable enable true 9f22be05-027c-470e-b138-4656b265436d @@ -14,6 +14,9 @@ + + + all runtime; build; native; contentfiles; analyzers; buildtransitive