Harden the content contracts and enforce the slug rule
This commit is contained in:
1 parent
d06af2891a
commit
0f7e968c16
13 files changed
+157
-81
No files matched your search
@@ -14,8 +14,13 @@ public record Event
|
||||
/// <summary>
|
||||
/// Gets the PocketBase record id.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <see langword="required"/>: every stored record has an id. Modeling it as
|
||||
/// required states which fields a record must carry, independent of the store,
|
||||
/// so a future data source has to supply them too.
|
||||
/// </remarks>
|
||||
[JsonPropertyName("id")]
|
||||
public string Id { get; init; } = "";
|
||||
public required string Id { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the start of the event as Europe/Berlin wall-clock time.
|
||||
@@ -24,10 +29,12 @@ public record Event
|
||||
/// PocketBase stores the value in UTC; it is converted to Berlin local time on
|
||||
/// deserialization, with daylight saving applied. An all-day event uses 00:00
|
||||
/// as the time.
|
||||
/// <see langword="required"/>: an event without a start has no place on the
|
||||
/// calendar, and the field is required in PocketBase.
|
||||
/// </remarks>
|
||||
[JsonPropertyName("start")]
|
||||
[JsonConverter(typeof(LocalDateTimeConverter))]
|
||||
public DateTime Start { get; init; }
|
||||
public required DateTime Start { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the optional end of the event as Europe/Berlin wall-clock time.
|
||||
@@ -42,8 +49,12 @@ public record Event
|
||||
/// <summary>
|
||||
/// Gets the event name, e.g. <c>"Elternbeiratssitzung"</c>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <see langword="required"/>: an event without a name is incomplete, and the
|
||||
/// field is required in PocketBase.
|
||||
/// </remarks>
|
||||
[JsonPropertyName("title")]
|
||||
public string Title { get; init; } = "";
|
||||
public required string Title { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the optional location, e.g. <c>"Aula"</c>.
|
||||
@@ -52,7 +63,7 @@ public record Event
|
||||
/// The location, or <see cref="string.Empty"/> if none is set.
|
||||
/// </value>
|
||||
[JsonPropertyName("location")]
|
||||
public string Location { get; init; } = "";
|
||||
public string Location { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the optional note, e.g. <c>"Anmeldung erforderlich"</c>.
|
||||
@@ -61,13 +72,7 @@ public record Event
|
||||
/// The note, or <see cref="string.Empty"/> if none is set.
|
||||
/// </value>
|
||||
[JsonPropertyName("note")]
|
||||
public string Note { get; init; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the event is visible to visitors of the site.
|
||||
/// </summary>
|
||||
[JsonPropertyName("public")]
|
||||
public bool Public { get; init; }
|
||||
public string Note { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the event has a wall-clock time, as opposed
|
||||
|
||||
@@ -13,30 +13,41 @@ public record Faq
|
||||
/// <summary>
|
||||
/// Gets the PocketBase record id.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <see langword="required"/>: every stored record has an id. Modeling it as
|
||||
/// required states which fields a record must carry, independent of the store,
|
||||
/// so a future data source has to supply them too.
|
||||
/// </remarks>
|
||||
[JsonPropertyName("id")]
|
||||
public string Id { get; init; } = "";
|
||||
public required string Id { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the question as a parent would phrase it.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <see langword="required"/>: a FAQ entry without a question is incomplete, and
|
||||
/// the field is required in PocketBase.
|
||||
/// </remarks>
|
||||
[JsonPropertyName("question")]
|
||||
public string Question { get; init; } = "";
|
||||
public required string Question { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the answer as Markdown.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <see langword="required"/>: a FAQ entry exists to answer its question, so an
|
||||
/// entry without an answer is incomplete. The field is required in PocketBase.
|
||||
/// </remarks>
|
||||
[JsonPropertyName("answer")]
|
||||
public string Answer { get; init; } = "";
|
||||
public required string Answer { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the topic the question is grouped under, e.g. <c>"mensa"</c>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <see langword="required"/>: the FAQ page groups entries by topic, so an entry
|
||||
/// without one has no place. The field is required in PocketBase.
|
||||
/// </remarks>
|
||||
[JsonPropertyName("topic")]
|
||||
public string Topic { get; init; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the question is visible to visitors of the site.
|
||||
/// </summary>
|
||||
[JsonPropertyName("public")]
|
||||
public bool Public { get; init; }
|
||||
public required string Topic { get; init; }
|
||||
}
|
||||
@@ -22,23 +22,30 @@ public record Page
|
||||
/// <summary>
|
||||
/// Gets the PocketBase record id.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <see langword="required"/>: every stored record has an id. Modeling it as
|
||||
/// required states which fields a record must carry, independent of the store,
|
||||
/// so a future data source has to supply them too.
|
||||
/// </remarks>
|
||||
[JsonPropertyName("id")]
|
||||
public string Id { get; init; } = "";
|
||||
public required string Id { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the heading shown to visitors.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Free text; may contain umlauts and spaces. For the URL, see <see cref="Slug"/>.
|
||||
/// <see langword="required"/>: a page without a heading is incomplete, and the
|
||||
/// field is required in PocketBase.
|
||||
/// </remarks>
|
||||
[JsonPropertyName("title")]
|
||||
public string Title { get; init; } = "";
|
||||
public required string Title { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the page body as Markdown.
|
||||
/// </summary>
|
||||
[JsonPropertyName("body")]
|
||||
public string Body { get; init; } = "";
|
||||
public string Body { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the navigation menu the page appears in.
|
||||
@@ -46,8 +53,12 @@ public record Page
|
||||
/// <value>
|
||||
/// Either <c>"header"</c> or <c>"footer"</c>.
|
||||
/// </value>
|
||||
/// <remarks>
|
||||
/// <see langword="required"/>: the navigation is built from this, and the field
|
||||
/// is required in PocketBase, so every page belongs to one of the two menus.
|
||||
/// </remarks>
|
||||
[JsonPropertyName("location")]
|
||||
public string Location { get; init; } = "";
|
||||
public required string Location { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the sort order within the navigation menu given by <see cref="Location"/>.
|
||||
@@ -62,10 +73,18 @@ public record Page
|
||||
/// Gets the URL slug of the page, e.g. <c>"board"</c> for <c>/board</c>.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A lowercase path segment without umlauts.
|
||||
/// A URL path segment: lowercase letters, digits and single hyphens as
|
||||
/// separators, no umlauts. PocketBase enforces this on save via a field
|
||||
/// pattern (<c>^[a-z0-9]+(-[a-z0-9]+)*$</c>), so every stored slug is already
|
||||
/// canonical and the app can use it verbatim in comparisons and generated URLs.
|
||||
/// </value>
|
||||
/// <remarks>
|
||||
/// <see langword="required"/>: the slug is how a page is addressed, so a record
|
||||
/// without one is broken. It is a required field in PocketBase, so deserializing
|
||||
/// one that lacks it should fail loudly rather than yield a page with no URL.
|
||||
/// </remarks>
|
||||
[JsonPropertyName("slug")]
|
||||
public string Slug { get; init; } = "";
|
||||
public required string Slug { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the dynamic blocks rendered below the <see cref="Body"/>.
|
||||
@@ -78,22 +97,20 @@ public record Page
|
||||
public IReadOnlyList<string> Embed { get; init; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the page is visible to visitors of the site.
|
||||
/// </summary>
|
||||
[JsonPropertyName("public")]
|
||||
public bool Public { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Tests whether a slug is the home page's, ignoring case. This is the single
|
||||
/// definition of that comparison, so every caller treats <c>home</c> and
|
||||
/// <c>Home</c> alike.
|
||||
/// Tests whether a slug is the home page's. This is the single definition of
|
||||
/// that comparison, so every caller identifies the home page the same way.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// An ordinal (case-sensitive) comparison is enough because slugs are always
|
||||
/// lowercase: PocketBase enforces that with a field pattern (see
|
||||
/// <see cref="Slug"/>), and this is only ever called with a stored slug.
|
||||
/// </remarks>
|
||||
/// <param name="slug">
|
||||
/// The slug to test.
|
||||
/// The slug to test, e.g. from <see cref="Slug"/>.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// <see langword="true"/> if <paramref name="slug"/> is the home page's slug.
|
||||
/// </returns>
|
||||
public static bool IsHomeSlug(string slug) =>
|
||||
string.Equals(slug, HomeSlug, StringComparison.OrdinalIgnoreCase);
|
||||
string.Equals(slug, HomeSlug, StringComparison.Ordinal);
|
||||
}
|
||||
@@ -13,8 +13,13 @@ public record Post
|
||||
/// <summary>
|
||||
/// Gets the PocketBase record id.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <see langword="required"/>: every stored record has an id. Modeling it as
|
||||
/// required states which fields a record must carry, independent of the store,
|
||||
/// so a future data source has to supply them too.
|
||||
/// </remarks>
|
||||
[JsonPropertyName("id")]
|
||||
public string Id { get; init; } = "";
|
||||
public required string Id { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the publication date as a calendar day.
|
||||
@@ -34,28 +39,32 @@ public record Post
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Free text; may contain umlauts and spaces. For the URL, see <see cref="Slug"/>.
|
||||
/// <see langword="required"/>: a post without a heading is incomplete, and the
|
||||
/// field is required in PocketBase.
|
||||
/// </remarks>
|
||||
[JsonPropertyName("title")]
|
||||
public string Title { get; init; } = "";
|
||||
public required string Title { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the post body as Markdown.
|
||||
/// </summary>
|
||||
[JsonPropertyName("body")]
|
||||
public string Body { get; init; } = "";
|
||||
public string Body { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the URL slug of the post, e.g. <c>"herbstbasar"</c> for <c>/posts/herbstbasar</c>.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A lowercase path segment without umlauts.
|
||||
/// A URL path segment: lowercase letters, digits and single hyphens as
|
||||
/// separators, no umlauts. PocketBase enforces this on save via a field
|
||||
/// pattern (<c>^[a-z0-9]+(-[a-z0-9]+)*$</c>), so every stored slug is already
|
||||
/// canonical and the app can use it verbatim in comparisons and generated URLs.
|
||||
/// </value>
|
||||
/// <remarks>
|
||||
/// <see langword="required"/>: the slug is how a post is addressed, so a record
|
||||
/// without one is broken. It is a required field in PocketBase, so deserializing
|
||||
/// one that lacks it should fail loudly rather than yield a post with no URL.
|
||||
/// </remarks>
|
||||
[JsonPropertyName("slug")]
|
||||
public string Slug { get; init; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the post is visible to visitors of the site.
|
||||
/// </summary>
|
||||
[JsonPropertyName("public")]
|
||||
public bool Public { get; init; }
|
||||
public required string Slug { get; init; }
|
||||
}
|
||||
Reference in new issue
Block a user