Skip to content

Commit

Permalink
update info response model
Browse files Browse the repository at this point in the history
  • Loading branch information
Kukks committed Oct 8, 2024
1 parent 5b79f4b commit ccd53d7
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 8 deletions.
50 changes: 42 additions & 8 deletions DotNut/ApiModels/GetInfoResponse.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,52 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using DotNut.JsonConverters;

namespace DotNut.ApiModels;

public class GetInfoResponse
{
[JsonPropertyName("name")] public string Name { get; set; }
[JsonPropertyName("pubkey")] public string Pubkey { get; set; }
[JsonPropertyName("version")] public string Version { get; set; }
[JsonPropertyName("description")] public string Description { get; set; }
[JsonPropertyName("description_long")] public string DescriptionLong { get; set; }
[JsonPropertyName("contact")] public List<ContactInfo> Contact { get; set; }
[JsonPropertyName("motd")] public string Motd { get; set; }
[JsonPropertyName("nuts")] public Dictionary<string, JsonDocument> Nuts { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[JsonPropertyName("name")]
public string? Name { get; set; }

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[JsonPropertyName("pubkey")]
public string? Pubkey { get; set; }

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[JsonPropertyName("version")]
public string? Version { get; set; }

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[JsonPropertyName("description")]
public string? Description { get; set; }

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[JsonPropertyName("description_long")]
public string? DescriptionLong { get; set; }

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[JsonPropertyName("contact")]
public List<ContactInfo>? Contact { get; set; }

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[JsonPropertyName("motd")]
public string? Motd { get; set; }


[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[JsonPropertyName("icon_url")]
public string? IconUrl { get; set; }

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[JsonConverter(typeof(UnixDateTimeOffsetConverter))]
[JsonPropertyName("time")]
public DateTimeOffset? Time { get; set; }

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[JsonPropertyName("nuts")]
public Dictionary<string, JsonDocument>? Nuts { get; set; }
}

public class ContactInfo
Expand Down
20 changes: 20 additions & 0 deletions DotNut/JsonConverters/UnixDateTimeOffsetConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Text.Json;
using System.Text.Json.Serialization;

namespace DotNut.JsonConverters;

public class UnixDateTimeOffsetConverter : JsonConverter<DateTimeOffset>
{
public override DateTimeOffset Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var val = reader.TokenType == JsonTokenType.Number? reader.GetInt64() : long.Parse(reader.GetString()!);


return DateTimeOffset.FromUnixTimeSeconds(val);
}

public override void Write(Utf8JsonWriter writer, DateTimeOffset value, JsonSerializerOptions options)
{
writer.WriteNumberValue(value.ToUnixTimeSeconds());
}
}

0 comments on commit ccd53d7

Please sign in to comment.