Files
Backend-Barracuda/SDG-Backend-Barracuda/Program.cs

42 lines
1.1 KiB
C#

using Dapper;
using Npgsql;
using SDG_Backend_Barracuda.Models;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();
// Register NpgsqlDataSource
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
builder.Services.AddNpgsqlDataSource(connectionString!);
// Register Data Tables
builder.Services.AddScoped<ICardModel, CardModel>();
var app = builder.Build();
// Ensure the table exists
using (var scope = app.Services.CreateScope())
{
var dataSource = scope.ServiceProvider.GetRequiredService<NpgsqlDataSource>();
await using var connection = await dataSource.OpenConnectionAsync();
await connection.ExecuteAsync(@"
CREATE TABLE IF NOT EXISTS ""Card"" (
""Id"" SERIAL PRIMARY KEY,
""Value"" TEXT NOT NULL
);");
}
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}
app.UseHttpsRedirection();
CardModel.MapEndpoints(app);
app.Run();