Refactoring API structure
This commit is contained in:
31
api/Public/Endpoints/PublicEndpoints.cs
Normal file
31
api/Public/Endpoints/PublicEndpoints.cs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
using Microsoft.Data.Sqlite;
|
||||||
|
|
||||||
|
public static class PublicEndpoints
|
||||||
|
{
|
||||||
|
public static void MapPublicEndpoints(WebApplication app)
|
||||||
|
{
|
||||||
|
app.MapGet("/", () =>
|
||||||
|
{
|
||||||
|
return new
|
||||||
|
{
|
||||||
|
Version = "1.0.0"
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.WithName("GetVersion");
|
||||||
|
|
||||||
|
app.MapGet("/health/db", async (SqliteConnection connection) =>
|
||||||
|
{
|
||||||
|
await connection.OpenAsync();
|
||||||
|
await using var command = connection.CreateCommand();
|
||||||
|
command.CommandText = "SELECT 1";
|
||||||
|
var result = await command.ExecuteScalarAsync();
|
||||||
|
|
||||||
|
return Results.Ok(new
|
||||||
|
{
|
||||||
|
Database = "ok",
|
||||||
|
Result = result
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.WithName("GetDatabaseHealth");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
using Microsoft.Data.Sqlite;
|
using Microsoft.Data.Sqlite;
|
||||||
|
|
||||||
|
public class Program
|
||||||
|
{
|
||||||
|
public static void Main(string[] args)
|
||||||
|
{
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
var configuredConnectionString = builder.Configuration.GetConnectionString("DefaultConnection")
|
var configuredConnectionString = builder.Configuration.GetConnectionString("DefaultConnection")
|
||||||
@@ -33,28 +37,8 @@ if (app.Environment.IsDevelopment())
|
|||||||
|
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
|
|
||||||
app.MapGet("/", () =>
|
PublicEndpoints.MapPublicEndpoints(app);
|
||||||
{
|
|
||||||
return new
|
|
||||||
{
|
|
||||||
Version = "1.0.0"
|
|
||||||
};
|
|
||||||
})
|
|
||||||
.WithName("GetVersion");
|
|
||||||
|
|
||||||
app.MapGet("/health/db", async (SqliteConnection connection) =>
|
|
||||||
{
|
|
||||||
await connection.OpenAsync();
|
|
||||||
await using var command = connection.CreateCommand();
|
|
||||||
command.CommandText = "SELECT 1";
|
|
||||||
var result = await command.ExecuteScalarAsync();
|
|
||||||
|
|
||||||
return Results.Ok(new
|
|
||||||
{
|
|
||||||
Database = "ok",
|
|
||||||
Result = result
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.WithName("GetDatabaseHealth");
|
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user