- New collection "documents" (title, slug, file, category, order, public); editors upload PDFs in the admin, no developer or redeploy needed - The app serves each file at /dokumente/<slug>.pdf, a URL that survives a new upload (PocketBase's own file name gets a random suffix) - New "documents" embed lists them as file cards, grouped by category; /downloads uses it - List/view rules are "public = true", so a draft PDF is not reachable through the PocketBase API either - Dev seed adds example documents with generated PDFs and fixes the const reassignment that broke seeding a fresh volume - Docs: editor guide, architecture, and the manual production setup steps Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
108 lines
4.1 KiB
C#
108 lines
4.1 KiB
C#
using System.Text.Json.Serialization;
|
|
|
|
namespace Elternbeirat.Contracts;
|
|
|
|
/// <summary>
|
|
/// A downloadable PDF (a form, a flyer, a letter to parents), as stored in PocketBase.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// The PDF itself is an upload in the record's <see cref="File"/> field, so an
|
|
/// editor adds or replaces a document in the PocketBase admin without a developer
|
|
/// or a redeploy. Visitors never see PocketBase's own file URL: the site serves the
|
|
/// file at <c>/dokumente/<slug>.pdf</c> (see <see cref="Path"/>).
|
|
/// </para>
|
|
/// <para>
|
|
/// That indirection exists because PocketBase appends a random suffix to every
|
|
/// stored file name, so its URL changes whenever an editor uploads a new version.
|
|
/// The slug stays, so a link in a page body, a letter or a printed QR code keeps
|
|
/// working across updates.
|
|
/// </para>
|
|
/// </remarks>
|
|
public record Document
|
|
{
|
|
/// <summary>
|
|
/// The URL path the site serves documents under.
|
|
/// </summary>
|
|
private const string PathPrefix = "/dokumente/";
|
|
|
|
/// <summary>
|
|
/// Gets the PocketBase record id.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <see langword="required"/>: every stored record has an id, and PocketBase's file
|
|
/// URL is built from it (<c>/api/files/documents/<id>/<file></c>).
|
|
/// </remarks>
|
|
[JsonPropertyName("id")]
|
|
public required string Id { get; init; }
|
|
|
|
/// <summary>
|
|
/// Gets the name shown on the file card, e.g. <c>"Aufnahmeantrag Förderverein"</c>.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <see langword="required"/>: a card without a name tells a visitor nothing, and
|
|
/// the field is required in PocketBase.
|
|
/// </remarks>
|
|
[JsonPropertyName("title")]
|
|
public required string Title { get; init; }
|
|
|
|
/// <summary>
|
|
/// Gets the slug the document is served under, e.g. <c>"einzugsermaechtigung"</c>
|
|
/// for <c>/dokumente/einzugsermaechtigung.pdf</c>.
|
|
/// </summary>
|
|
/// <value>
|
|
/// Lowercase letters, digits and single hyphens, no umlauts. PocketBase enforces the
|
|
/// same pattern as for <see cref="Page.Slug"/> and a unique index, so every slug
|
|
/// names exactly one document.
|
|
/// </value>
|
|
/// <remarks>
|
|
/// <see langword="required"/>: the slug is how the document is addressed.
|
|
/// </remarks>
|
|
[JsonPropertyName("slug")]
|
|
public required string Slug { get; init; }
|
|
|
|
/// <summary>
|
|
/// Gets the name PocketBase stored the uploaded PDF under.
|
|
/// </summary>
|
|
/// <value>
|
|
/// The stored file name including PocketBase's random suffix, e.g.
|
|
/// <c>"einzugsermaechtigung_k2j4h5g6f7.pdf"</c>. Only used to fetch the file from
|
|
/// PocketBase; never shown or linked.
|
|
/// </value>
|
|
/// <remarks>
|
|
/// <see langword="required"/>: a document without a file has nothing to download,
|
|
/// and the field is required in PocketBase.
|
|
/// </remarks>
|
|
[JsonPropertyName("file")]
|
|
public required string File { get; init; }
|
|
|
|
/// <summary>
|
|
/// Gets the optional group the document is listed under, e.g. <c>"Förderverein"</c>.
|
|
/// </summary>
|
|
/// <value>
|
|
/// The group heading, or <see cref="string.Empty"/> for a document listed without one.
|
|
/// </value>
|
|
[JsonPropertyName("category")]
|
|
public string Category { get; init; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// Gets the sort order in the download list.
|
|
/// </summary>
|
|
/// <value>
|
|
/// The sort key; documents with smaller values appear first. Groups appear in the
|
|
/// order of their first document.
|
|
/// </value>
|
|
[JsonPropertyName("order")]
|
|
public double Order { get; init; }
|
|
|
|
/// <summary>
|
|
/// Gets the site-relative URL the document is served at.
|
|
/// </summary>
|
|
/// <value>
|
|
/// <c>/dokumente/<slug>.pdf</c>. The <c>.pdf</c> ending is what the stylesheet
|
|
/// keys the file icon and the file card off.
|
|
/// </value>
|
|
[JsonIgnore]
|
|
public string Path => $"{PathPrefix}{Slug}.pdf";
|
|
}
|