Move date converters onto the contracts
This commit is contained in:
1 parent
6d3260db49
commit
31b114982e
6 files changed
+29
-23
No files matched your search
@@ -24,7 +24,7 @@ namespace Elternbeirat.PocketBase;
|
||||
public sealed class PocketBaseClient(HttpClient http)
|
||||
{
|
||||
/// <summary>
|
||||
/// Serializer options that map PocketBase UTC dates to Berlin wall-clock time.
|
||||
/// Shared serializer options for every request; see <see cref="CreateJsonOptions"/>.
|
||||
/// </summary>
|
||||
private static readonly JsonSerializerOptions JsonOptions = CreateJsonOptions();
|
||||
|
||||
@@ -83,23 +83,16 @@ public sealed class PocketBaseClient(HttpClient http)
|
||||
=> GetRecordsAsync<Faq>("faqs", "topic", ct);
|
||||
|
||||
/// <summary>
|
||||
/// Creates the serializer options with the date converters registered: the
|
||||
/// wall-clock ones for points in time and the calendar-day one for plain dates.
|
||||
/// Creates the serializer options. Date handling lives on the contracts
|
||||
/// themselves via <c>[JsonConverter]</c> on each date field (e.g.
|
||||
/// <see cref="Contracts.Event.Start"/>, <see cref="Contracts.Post.Date"/>), so
|
||||
/// nothing date-related is registered here.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The configured options.
|
||||
/// </returns>
|
||||
private static JsonSerializerOptions CreateJsonOptions()
|
||||
{
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
};
|
||||
options.Converters.Add(new LocalDateTimeConverter());
|
||||
options.Converters.Add(new NullableLocalDateTimeConverter());
|
||||
options.Converters.Add(new DateOnlyConverter());
|
||||
return options;
|
||||
}
|
||||
private static JsonSerializerOptions CreateJsonOptions() =>
|
||||
new() { PropertyNameCaseInsensitive = true };
|
||||
|
||||
/// <summary>
|
||||
/// Gets all public records of a collection in a single request.
|
||||
|
||||
Reference in new issue
Block a user