using System.Text.Json.Serialization; namespace Elternbeirat.Contracts; /// /// A downloadable PDF (a form, a flyer, a letter to parents), as stored in PocketBase. /// /// /// /// The PDF itself is an upload in the record's 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 /dokumente/<slug>.pdf (see ). /// /// /// 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. /// /// public record Document { /// /// The URL path the site serves documents under. /// private const string PathPrefix = "/dokumente/"; /// /// Gets the PocketBase record id. /// /// /// : every stored record has an id, and PocketBase's file /// URL is built from it (/api/files/documents/<id>/<file>). /// [JsonPropertyName("id")] public required string Id { get; init; } /// /// Gets the name shown on the file card, e.g. "Aufnahmeantrag Förderverein". /// /// /// : a card without a name tells a visitor nothing, and /// the field is required in PocketBase. /// [JsonPropertyName("title")] public required string Title { get; init; } /// /// Gets the slug the document is served under, e.g. "einzugsermaechtigung" /// for /dokumente/einzugsermaechtigung.pdf. /// /// /// Lowercase letters, digits and single hyphens, no umlauts. PocketBase enforces the /// same pattern as for and a unique index, so every slug /// names exactly one document. /// /// /// : the slug is how the document is addressed. /// [JsonPropertyName("slug")] public required string Slug { get; init; } /// /// Gets the name PocketBase stored the uploaded PDF under. /// /// /// The stored file name including PocketBase's random suffix, e.g. /// "einzugsermaechtigung_k2j4h5g6f7.pdf". Only used to fetch the file from /// PocketBase; never shown or linked. /// /// /// : a document without a file has nothing to download, /// and the field is required in PocketBase. /// [JsonPropertyName("file")] public required string File { get; init; } /// /// Gets the optional group the document is listed under, e.g. "Förderverein". /// /// /// The group heading, or for a document listed without one. /// [JsonPropertyName("category")] public string Category { get; init; } = string.Empty; /// /// Gets the sort order in the download list. /// /// /// The sort key; documents with smaller values appear first. Groups appear in the /// order of their first document. /// [JsonPropertyName("order")] public double Order { get; init; } /// /// Gets the site-relative URL the document is served at. /// /// /// /dokumente/<slug>.pdf. The .pdf ending is what the stylesheet /// keys the file icon and the file card off. /// [JsonIgnore] public string Path => $"{PathPrefix}{Slug}.pdf"; }