84 lines
2.8 KiB
C#
84 lines
2.8 KiB
C#
using System.Text.Json.Serialization;
|
|
|
|
namespace Elternbeirat.Contracts;
|
|
|
|
/// <summary>
|
|
/// A calendar entry of the Elternbeirat, as stored in PocketBase.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Event lists are ordered by <see cref="Start"/>. Unset optional text fields are
|
|
/// <see cref="string.Empty"/>, never <see langword="null"/>.
|
|
/// </remarks>
|
|
public record Event
|
|
{
|
|
/// <summary>
|
|
/// Gets the PocketBase record id.
|
|
/// </summary>
|
|
[JsonPropertyName("id")]
|
|
public string Id { get; init; } = "";
|
|
|
|
/// <summary>
|
|
/// Gets the start of the event as Europe/Berlin wall-clock time.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// 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.
|
|
/// </remarks>
|
|
[JsonPropertyName("start")]
|
|
[JsonConverter(typeof(LocalDateTimeConverter))]
|
|
public DateTime Start { get; init; }
|
|
|
|
/// <summary>
|
|
/// Gets the optional end of the event as Europe/Berlin wall-clock time.
|
|
/// </summary>
|
|
/// <value>
|
|
/// The end time, or <see langword="null"/> if the event has no end.
|
|
/// </value>
|
|
[JsonPropertyName("end")]
|
|
[JsonConverter(typeof(NullableLocalDateTimeConverter))]
|
|
public DateTime? End { get; init; }
|
|
|
|
/// <summary>
|
|
/// Gets the event name, e.g. <c>"Elternbeiratssitzung"</c>.
|
|
/// </summary>
|
|
[JsonPropertyName("title")]
|
|
public string Title { get; init; } = "";
|
|
|
|
/// <summary>
|
|
/// Gets the optional location, e.g. <c>"Aula"</c>.
|
|
/// </summary>
|
|
/// <value>
|
|
/// The location, or <see cref="string.Empty"/> if none is set.
|
|
/// </value>
|
|
[JsonPropertyName("location")]
|
|
public string Location { get; init; } = "";
|
|
|
|
/// <summary>
|
|
/// Gets the optional note, e.g. <c>"Anmeldung erforderlich"</c>.
|
|
/// </summary>
|
|
/// <value>
|
|
/// 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; }
|
|
|
|
/// <summary>
|
|
/// Gets a value indicating whether the event has a wall-clock time, as opposed
|
|
/// to being an all-day event.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// PocketBase has no all-day flag; the convention is that a start of 00:00
|
|
/// means all-day. This is the single definition of that rule -- formatting and
|
|
/// the calendar feed both read it here instead of re-deriving it.
|
|
/// </remarks>
|
|
[JsonIgnore]
|
|
public bool HasTime => Start.TimeOfDay != TimeSpan.Zero;
|
|
}
|