mirror of
https://gitea.tendokyu.moe/ppc/amnet.git
synced 2026-09-22 22:28:22 +03:00
merge serializer contents into webserver class
This commit is contained in:
@@ -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;
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user