Persistenz: SQLite + Dapper, chains/messages Tabellen, History-Endpoint, Frontend History-Load

This commit is contained in:
Meleki committed 2026-02-26 15:21:34 +01:00
1 parent 5f210323fd
commit 9f2f3fee1f
9 files changed
+370 -6

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Gott.Models;
using Gott.Services;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
namespace Gott.Endpoints;
public static class HistoryEndpoint
{
public static void MapHistoryEndpoint(this IEndpointRouteBuilder app)
{
app.MapGet("/api/history", HandleHistory);
}
private static async Task HandleHistory(HttpContext ctx, DatabaseService db)
{
var sessionId = ctx.Request.Query["sessionId"].FirstOrDefault();
var limitStr = ctx.Request.Query["limit"].FirstOrDefault();
var limit = int.TryParse(limitStr, out var l) ? l : 50;
IEnumerable<ChainRecord> chains;
if (string.IsNullOrEmpty(sessionId) || sessionId == "null")
chains = await db.GetRecentChains(limit);
else
chains = await db.GetSessionChains(sessionId, limit);
var result = new List<object>();
foreach (var chain in chains)
{
var messages = await db.GetChainMessages(chain.ChainId);
result.Add(new { chain, messages });
}
await ctx.Response.WriteAsJsonAsync(result);
}
}