Harden the content contracts and enforce the slug rule

This commit is contained in:
tleininger committed 2026-09-24 12:08:56 +02:00
1 parent d06af2891a
commit 0f7e968c16
13 files changed
+157 -81

No files matched your search

+15 -15
View File
@@ -24,15 +24,15 @@ namespace Elternbeirat.PocketBase;
/// <see cref="HttpClient.BaseAddress"/> set to the PocketBase base URL.
/// </para>
/// </remarks>
/// <param name="http">
/// <param name="httpClient">
/// The HTTP client; its <see cref="HttpClient.BaseAddress"/> must point to PocketBase.
/// </param>
public sealed class PocketBaseClient(HttpClient http)
public sealed class PocketBaseClient(HttpClient httpClient)
{
/// <summary>
/// Gets all public pages, ordered by <see cref="Page.Order"/>.
/// </summary>
/// <param name="ct">
/// <param name="token">
/// A token to cancel the request.
/// </param>
/// <returns>
@@ -45,10 +45,10 @@ public sealed class PocketBaseClient(HttpClient http)
/// The response could not be deserialized.
/// </exception>
/// <exception cref="OperationCanceledException">
/// <paramref name="ct"/> was canceled or the request timed out.
/// <paramref name="token"/> was canceled or the request timed out.
/// </exception>
public Task<IReadOnlyList<Page>> GetPagesAsync(CancellationToken ct = default)
=> GetRecordsAsync<Page>("pages", "order", ct);
public Task<IReadOnlyList<Page>> GetPagesAsync(CancellationToken token = default)
=> GetRecordsAsync<Page>("pages", "order", token);
/// <summary>
/// Gets all public posts, ordered by <see cref="Post.Date"/>, newest first.
@@ -58,8 +58,8 @@ public sealed class PocketBaseClient(HttpClient http)
/// The public posts, or an empty list if there are none.
/// </returns>
/// <inheritdoc cref="GetPagesAsync" path="/exception"/>
public Task<IReadOnlyList<Post>> GetPostsAsync(CancellationToken ct = default)
=> GetRecordsAsync<Post>("posts", "-date", ct);
public Task<IReadOnlyList<Post>> GetPostsAsync(CancellationToken token = default)
=> GetRecordsAsync<Post>("posts", "-date", token);
/// <summary>
/// Gets all public events, ordered by <see cref="Event.Start"/>, earliest first.
@@ -69,8 +69,8 @@ public sealed class PocketBaseClient(HttpClient http)
/// The public events, or an empty list if there are none.
/// </returns>
/// <inheritdoc cref="GetPagesAsync" path="/exception"/>
public Task<IReadOnlyList<Event>> GetEventsAsync(CancellationToken ct = default)
=> GetRecordsAsync<Event>("events", "start", ct);
public Task<IReadOnlyList<Event>> GetEventsAsync(CancellationToken token = default)
=> GetRecordsAsync<Event>("events", "start", token);
/// <summary>
/// Gets all public FAQ entries, ordered by <see cref="Faq.Topic"/>.
@@ -80,8 +80,8 @@ public sealed class PocketBaseClient(HttpClient http)
/// The public FAQ entries, or an empty list if there are none.
/// </returns>
/// <inheritdoc cref="GetPagesAsync" path="/exception"/>
public Task<IReadOnlyList<Faq>> GetFaqsAsync(CancellationToken ct = default)
=> GetRecordsAsync<Faq>("faqs", "topic", ct);
public Task<IReadOnlyList<Faq>> GetFaqsAsync(CancellationToken token = default)
=> GetRecordsAsync<Faq>("faqs", "topic", token);
/// <summary>
/// Gets all public records of a collection in a single request.
@@ -95,7 +95,7 @@ public sealed class PocketBaseClient(HttpClient http)
/// <param name="sort">
/// The PocketBase sort expression; a leading <c>-</c> sorts descending.
/// </param>
/// <param name="ct">
/// <param name="token">
/// A token to cancel the request.
/// </param>
/// <returns>
@@ -104,7 +104,7 @@ public sealed class PocketBaseClient(HttpClient http)
private async Task<IReadOnlyList<T>> GetRecordsAsync<T>(
string collection,
string sort,
CancellationToken ct)
CancellationToken token)
{
// filter=public=true keeps drafts out; perPage is large enough to fetch
// every record in a single page given the small content volume.
@@ -112,7 +112,7 @@ public sealed class PocketBaseClient(HttpClient http)
+ $"?perPage=500&filter={Uri.EscapeDataString("public=true")}"
+ $"&sort={Uri.EscapeDataString(sort)}";
var result = await http.GetFromJsonAsync<RecordList<T>>(url, ct);
var result = await httpClient.GetFromJsonAsync<RecordList<T>>(url, token);
return result?.Items ?? [];
}
}