Added MidrandBooks project

This commit is contained in:
Khwezi Mngoma
2026-05-24 13:38:47 +02:00
parent 70c6e0bfbc
commit f67f5eaf53
17 changed files with 241 additions and 46 deletions
@@ -15,7 +15,7 @@ public static class HealthChecks
public static IServiceCollection AddShopPostgresHealthCheck(this IServiceCollection services)
{
services.AddHealthChecks().AddCheck<PostgresShopHealthCheck>(ShopDbConfigName);
services.AddHealthChecks().AddCheck<PostgresShopHealthCheck>(TechShopDbConfigName);
return services;
}
@@ -4,12 +4,12 @@ namespace LiteCharms.Features.TechShop.Extensions;
public static class Postgres
{
public const string ShopDbConfigName = "PostgresShop";
public const string TechShopDbConfigName = "PostgresShop";
public static IServiceCollection AddTechShopDatabase(this IServiceCollection services, IConfiguration configuration)
{
services.AddPooledDbContextFactory<ShopDbContext>(options =>
options.UseNpgsql(configuration.GetConnectionString(ShopDbConfigName)));
options.UseNpgsql(configuration.GetConnectionString(TechShopDbConfigName)));
return services;
}
@@ -4,7 +4,7 @@ namespace LiteCharms.Features.TechShop.HealthChecks;
public class PostgresShopHealthCheck(IConfiguration configuration) : IHealthCheck
{
private readonly string connectionString = configuration.GetConnectionString(ShopDbConfigName)!;
private readonly string connectionString = configuration.GetConnectionString(TechShopDbConfigName)!;
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
{
@@ -18,11 +18,11 @@ public class PostgresShopHealthCheck(IConfiguration configuration) : IHealthChec
await command.ExecuteScalarAsync(cancellationToken);
return HealthCheckResult.Healthy($"{ShopDbConfigName} is responsive.");
return HealthCheckResult.Healthy($"{TechShopDbConfigName} is responsive.");
}
catch (Exception ex)
{
return HealthCheckResult.Unhealthy($"{ShopDbConfigName} is unreachable.", ex);
return HealthCheckResult.Unhealthy($"{TechShopDbConfigName} is unreachable.", ex);
}
}
}
@@ -8,21 +8,21 @@ public class ShopQuartzHealthCheck(ISchedulerFactory schedulerFactory) : IHealth
{
try
{
var scheduler = await schedulerFactory.GetScheduler(ShopSchedulerName, cancellationToken);
var scheduler = await schedulerFactory.GetScheduler(TechShopSchedulerName, cancellationToken);
if(scheduler == null)
return HealthCheckResult.Unhealthy($"Scheduler with name '{ShopSchedulerName}' not found.");
return HealthCheckResult.Unhealthy($"Scheduler with name '{TechShopSchedulerName}' not found.");
if (!scheduler.IsStarted)
return HealthCheckResult.Unhealthy($"{ShopSchedulerName} Quartz scheduler is not running");
return HealthCheckResult.Unhealthy($"{TechShopSchedulerName} Quartz scheduler is not running");
await scheduler.CheckExists(new JobKey(Guid.NewGuid().ToString()), cancellationToken);
return HealthCheckResult.Healthy($"{ShopSchedulerName} Quartz scheduler is ready");
return HealthCheckResult.Healthy($"{TechShopSchedulerName} Quartz scheduler is ready");
}
catch (SchedulerException)
{
return HealthCheckResult.Unhealthy($"{ShopSchedulerName} Quartz scheduler cannot connect to the store");
return HealthCheckResult.Unhealthy($"{TechShopSchedulerName} Quartz scheduler cannot connect to the store");
}
}
}
@@ -14,7 +14,7 @@ public class ShopDbContextFactory : IDesignTimeDbContextFactory<ShopDbContext>
.Build();
var optionsBuilder = new DbContextOptionsBuilder<ShopDbContext>();
optionsBuilder.UseNpgsql(configuration.GetConnectionString(ShopDbConfigName));
optionsBuilder.UseNpgsql(configuration.GetConnectionString(TechShopDbConfigName));
return new ShopDbContext(optionsBuilder.Options);
}