feat: add debug registration endpoint, fix snowflake serialization

This commit is contained in:
sam 2024-06-04 17:38:59 +02:00
parent 852036a6f7
commit 588afeec20
14 changed files with 646 additions and 10 deletions

View file

@ -1,9 +1,11 @@
using System.Diagnostics.CodeAnalysis;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Newtonsoft.Json;
using NodaTime;
namespace Foxnouns.Backend.Database;
[JsonConverter(typeof(JsonConverter))]
public readonly struct Snowflake(ulong value)
{
public const long Epoch = 1_640_995_200_000; // 2022-01-01 at 00:00:00 UTC
@ -63,4 +65,19 @@ public readonly struct Snowflake(ulong value)
convertToProviderExpression: x => x,
convertFromProviderExpression: x => x
);
private class JsonConverter : JsonConverter<Snowflake>
{
public override void WriteJson(JsonWriter writer, Snowflake value, JsonSerializer serializer)
{
writer.WriteValue(value.Value.ToString());
}
public override Snowflake ReadJson(JsonReader reader, Type objectType, Snowflake existingValue,
bool hasExistingValue,
JsonSerializer serializer)
{
return ulong.Parse((string)reader.Value!);
}
}
}