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
@@ -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