Consume PocketBase for posts and events, with English routes

This commit is contained in:
tleininger committed 2026-09-23 13:09:22 +02:00
1 parent c59e7a4f83
commit da87716d97
22 files changed
+278 -225

No files matched your search

+26 -4
View File
@@ -1,3 +1,5 @@
using Elternbeirat.Contracts;
using Elternbeirat.PocketBase;
using Elternbeirat.Web.Components;
using Elternbeirat.Web.Features.Events;
using Elternbeirat.Web.Services;
@@ -8,10 +10,17 @@ var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorComponents();
// The typed client reads content from PocketBase over its REST API. The base URL
// comes from configuration: appsettings for local dev, the PocketBase__BaseUrl
// env var on the server (see compose.yaml).
var pocketBaseUrl = builder.Configuration["PocketBase:BaseUrl"]
?? throw new InvalidOperationException("PocketBase:BaseUrl is not configured.");
builder.Services.AddHttpClient<PocketBaseClient>(client =>
client.BaseAddress = new Uri(pocketBaseUrl));
// Content is read once at startup and cached -> singletons.
builder.Services.AddSingleton<PageService>();
builder.Services.AddSingleton<PostService>();
builder.Services.AddSingleton<EventService>();
var app = builder.Build();
@@ -43,8 +52,21 @@ app.MapStaticAssets();
app.MapRazorComponents<App>();
// Subscribable calendar feed of all events. A minimal API endpoint rather than
// a Razor page because it returns text/calendar, not HTML.
app.MapGet("/termine.ics", (EventService events) =>
Results.Text(IcsCalendar.Build(events.All), "text/calendar; charset=utf-8"));
// a Razor page because it returns text/calendar, not HTML. Reads from PocketBase
// per request; an unreachable source yields an empty calendar, not a 500.
app.MapGet("/events.ics", async (PocketBaseClient pocketBase) =>
{
IReadOnlyList<Event> events;
try
{
events = await pocketBase.GetEventsAsync();
}
catch (HttpRequestException)
{
events = [];
}
return Results.Text(IcsCalendar.Build(events), "text/calendar; charset=utf-8");
});
app.Run();