Rename Public -> App

This commit is contained in:
2026-02-17 22:00:59 +02:00
parent 13ca568244
commit 46bdad7296
13 changed files with 6 additions and 6 deletions

14
api/App/App.csproj Normal file
View File

@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.0" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="10.0.0" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,21 @@
public static class LokEndpoints
{
public static void MapLokEndpoints(WebApplication app)
{
app.MapGet("/lok/open-hours", async (LokService lokService) =>
{
var openHours = await lokService.GetOpenHoursAsync();
if (openHours is null)
{
return Results.NotFound(new
{
Message = "Open hours not found."
});
}
return Results.Ok(openHours);
})
.WithName("GetLokOpenHours");
}
}

View File

@@ -0,0 +1,31 @@
using Microsoft.Data.Sqlite;
public static class SystemEndpoints
{
public static void MapSystemEndpoints(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");
}
}

View File

@@ -0,0 +1,12 @@
public class LokOpenHours
{
public string Paragraph1 { get; set; } = string.Empty;
public string Paragraph2 { get; set; } = string.Empty;
public string Paragraph3 { get; set; } = string.Empty;
public string Paragraph4 { get; set; } = string.Empty;
public string KitchenNotice { get; set; } = string.Empty;
}

61
api/App/Program.cs Normal file
View File

@@ -0,0 +1,61 @@
using Microsoft.Data.Sqlite;
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
var configuredConnectionString = builder.Configuration.GetConnectionString("DefaultConnection")
?? throw new InvalidOperationException("Connection string 'DefaultConnection' was not found.");
var sqliteConnectionStringBuilder = new SqliteConnectionStringBuilder(configuredConnectionString);
var databasePath = Path.GetFullPath(Path.Combine(builder.Environment.ContentRootPath, sqliteConnectionStringBuilder.DataSource));
var databaseDirectory = Path.GetDirectoryName(databasePath)
?? throw new InvalidOperationException("Could not determine database directory.");
Directory.CreateDirectory(databaseDirectory);
sqliteConnectionStringBuilder.DataSource = databasePath;
var resolvedConnectionString = sqliteConnectionStringBuilder.ToString();
builder.Services.AddScoped(_ => new SqliteConnection(resolvedConnectionString));
builder.Services.AddScoped<LokService>();
builder.Services.AddOpenApi();
var app = builder.Build();
using (var connection = new SqliteConnection(resolvedConnectionString))
{
connection.Open();
var initScriptPath = Path.GetFullPath(Path.Combine(builder.Environment.ContentRootPath, "../Database/init.sql"));
if (File.Exists(initScriptPath))
{
var initSql = File.ReadAllText(initScriptPath);
if (!string.IsNullOrWhiteSpace(initSql))
{
using (var command = connection.CreateCommand())
{
command.CommandText = initSql;
command.ExecuteNonQuery();
}
}
}
}
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}
app.UseHttpsRedirection();
SystemEndpoints.MapSystemEndpoints(app);
LokEndpoints.MapLokEndpoints(app);
app.Run();
}
}

View File

@@ -0,0 +1,23 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "http://localhost:5013",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "https://localhost:7064;http://localhost:5013",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@@ -0,0 +1,42 @@
using System.Data;
using Microsoft.Data.Sqlite;
public class LokService
{
private readonly SqliteConnection _connection;
public LokService(SqliteConnection connection)
{
_connection = connection;
}
public async Task<LokOpenHours?> GetOpenHoursAsync()
{
if (_connection.State != ConnectionState.Open)
{
await _connection.OpenAsync();
}
await using var command = _connection.CreateCommand();
command.CommandText = @"
SELECT paragraph1, paragraph2, paragraph3, paragraph4, kitchenNotice
FROM LokOpenHours
LIMIT 1";
await using var reader = await command.ExecuteReaderAsync();
if (!await reader.ReadAsync())
{
return null;
}
return new LokOpenHours
{
Paragraph1 = reader["paragraph1"]?.ToString() ?? string.Empty,
Paragraph2 = reader["paragraph2"]?.ToString() ?? string.Empty,
Paragraph3 = reader["paragraph3"]?.ToString() ?? string.Empty,
Paragraph4 = reader["paragraph4"]?.ToString() ?? string.Empty,
KitchenNotice = reader["kitchenNotice"]?.ToString() ?? string.Empty
};
}
}

View File

@@ -0,0 +1,11 @@
{
"ConnectionStrings": {
"DefaultConnection": "Data Source=../Database/klapi.db"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

12
api/App/appsettings.json Normal file
View File

@@ -0,0 +1,12 @@
{
"ConnectionStrings": {
"DefaultConnection": "Data Source=../Database/klapi.db"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}