Implement US-04 blood-pressure observation recording

This commit is contained in:
Steffen committed 2026-10-01 11:55:31 +02:00
1 parent a9633e49e1
commit 05f57dcba3
25 files changed
+843 -9

No files matched your search

+48
View File
@@ -0,0 +1,48 @@
using Microsoft.EntityFrameworkCore;
using ObservationService.Application;
using ObservationService.Persistence;
namespace ObservationService;
public class Program
{
public static async Task Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddProblemDetails();
builder.Services.AddDbContext<ObservationDbContext>((services, options) =>
options.UseNpgsql(services.GetRequiredService<IConfiguration>().GetConnectionString("ObservationDatabase")));
builder.Services.AddScoped<ObservationRepository, SqlObservationRepository>();
builder.Services.AddScoped<ObservationApplicationService>();
builder.Services.AddHttpClient("ApiGateway", (services, client) =>
client.BaseAddress = GetGatewayUri(services.GetRequiredService<IConfiguration>()))
.ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler { AllowAutoRedirect = false });
var app = builder.Build();
if (string.IsNullOrWhiteSpace(app.Configuration.GetConnectionString("ObservationDatabase")))
throw new InvalidOperationException("ConnectionStrings:ObservationDatabase must be configured.");
if (args.Contains("--migrate"))
{
await using var scope = app.Services.CreateAsyncScope();
await scope.ServiceProvider.GetRequiredService<ObservationDbContext>().Database.MigrateAsync();
return;
}
_ = GetGatewayUri(app.Configuration);
app.UseExceptionHandler();
app.MapControllers();
await app.RunAsync();
}
private static Uri GetGatewayUri(IConfiguration configuration)
{
var endpoint = configuration["Services:ApiGateway:BaseUrl"];
if (!Uri.TryCreate(endpoint, UriKind.Absolute, out var uri) ||
(uri.Scheme != "http" && uri.Scheme != "https") || uri.AbsolutePath != "/" ||
!string.IsNullOrEmpty(uri.Query) || !string.IsNullOrEmpty(uri.Fragment) || !string.IsNullOrEmpty(uri.UserInfo))
throw new InvalidOperationException("Services:ApiGateway:BaseUrl must be an HTTP(S) origin URL.");
return uri;
}
}