diff --git a/AMNet.Server/SerializerContext.cs b/AMNet.Server/SerializerContext.cs deleted file mode 100644 index ce14208..0000000 --- a/AMNet.Server/SerializerContext.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Text.Json.Serialization; - -namespace AMNet.Server; - -public record SystemState( - [property: JsonPropertyName("apiVersion")] int ApiVersion, - [property: JsonPropertyName("gameId")] string GameId, - [property: JsonPropertyName("serverName")] string ServerName, - [property: JsonPropertyName("sessionUptime")] long SessionUptime, - [property: JsonPropertyName("timeSinceLastPoll")] long? TimeSinceLastPoll); - -public record CardReadRequest( - [property: JsonPropertyName("cardId")] string MatrixCode); - -[JsonSerializable(typeof(SystemState))] -[JsonSerializable(typeof(CardReadRequest))] -[JsonSourceGenerationOptions(WriteIndented = true)] -public partial class SerializerContext : JsonSerializerContext; \ No newline at end of file diff --git a/AMNet.Server/WebServer.cs b/AMNet.Server/WebServer.cs index c4dbe85..6fc9d24 100644 --- a/AMNet.Server/WebServer.cs +++ b/AMNet.Server/WebServer.cs @@ -1,6 +1,7 @@ using System; using System.Globalization; using System.Text.Json; +using System.Text.Json.Serialization; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; @@ -11,10 +12,20 @@ using Microsoft.Extensions.Logging; namespace AMNet.Server; -internal static class WebServer +internal static partial class WebServer { private const int ApiVersion = 1; + public record SystemState( + [property: JsonPropertyName("apiVersion")] int ApiVersion, + [property: JsonPropertyName("gameId")] string GameId, + [property: JsonPropertyName("serverName")] string ServerName, + [property: JsonPropertyName("sessionUptime")] long SessionUptime, + [property: JsonPropertyName("timeSinceLastPoll")] long? TimeSinceLastPoll); + + public record CardReadRequest( + [property: JsonPropertyName("cardId")] string MatrixCode); + public static WebApplication BuildServer(params string[] listenAddresses) { var builder = WebApplication.CreateSlimBuilder([]); @@ -128,4 +139,9 @@ internal static class WebServer await ctx.Response.WriteAsync("Invalid card id format."); } } + + [JsonSerializable(typeof(SystemState))] + [JsonSerializable(typeof(CardReadRequest))] + [JsonSourceGenerationOptions(WriteIndented = true)] + private partial class SerializerContext : JsonSerializerContext; } \ No newline at end of file