Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api type fixes #502

Merged
merged 3 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

public class ApiGetMemberShip2Request
{
[JsonPropertyName("api_sort_key")]
public string ApiSortKey { get; set; } = "";
[JsonPropertyName("api_token")]
public required string ApiToken { get; set; }

[JsonPropertyName("api_verno")]
public string ApiVerno { get; set; } = "";
public required string ApiVerno { get; set; }

[JsonPropertyName("api_sort_key")]
public required string ApiSortKey { get; set; }

[JsonPropertyName("spi_sort_order")]
public string SpiSortOrder { get; set; } = "";
public required string SpiSortOrder { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace ElectronicObserver.KancolleApi.Types.ApiReqAirCorps.ExpandBase;

public class ApiReqAirCorpsExpandBaseRequest
{
[JsonPropertyName("api_token")]
public required string ApiToken { get; set; }

[JsonPropertyName("api_verno")]
public required string ApiVerno { get; set; }

[JsonPropertyName("api_area_id")]
public required string ApiAreaId { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using ElectronicObserver.KancolleApi.Types.Models;

namespace ElectronicObserver.KancolleApi.Types.ApiReqAirCorps.ExpandBase;

public class ApiReqAirCorpsExpandBaseResponse : ApiAirBase;
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
using ElectronicObserver.KancolleApi.Types.Interfaces;
namespace ElectronicObserver.KancolleApi.Types.ApiReqCombinedBattle.LdShooting;

namespace ElectronicObserver.KancolleApi.Types.ApiReqCombinedBattle.LdShooting;

public class ApiReqCombinedBattleLdShootingRequest : IBattleApiRequest
public class ApiReqCombinedBattleLdShootingRequest
{
/// <inheritdoc />
[JsonPropertyName("api_smoke_flag")]
public string? ApiSmokeFlag { get; set; }
[JsonPropertyName("api_token")]
public required string ApiToken { get; set; }

[JsonPropertyName("api_verno")]
public required string ApiVerno { get; set; }

[JsonPropertyName("api_formation")]
public required string ApiFormation { get; set; }

[JsonPropertyName("api_recovery_type")]
public required string ApiRecoveryType { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ public class ApiReqFurnitureChangeRequest

[JsonPropertyName("api_window")]
public string ApiWindow { get; set; } = "";

[JsonPropertyName("api_bgm_id")]
public string? ApiBgmId { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
namespace ElectronicObserver.KancolleApi.Types.ApiReqFurniture.Change;

public class ApiReqFurnitureChangeResponse
{
[JsonPropertyName("api_result")]
public int ApiResult { get; set; }

[JsonPropertyName("api_result_msg")]
public string ApiResultMsg { get; set; } = "";
}
/// <summary>
/// There's no response data.
/// </summary>
public class ApiReqFurnitureChangeResponse;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace ElectronicObserver.KancolleApi.Types.ApiReqKaisou.PresetSlotDelete;

public class ApiReqKaisouPresetSlotDeleteRequest
{
[JsonPropertyName("api_token")]
public required string ApiToken { get; set; }

[JsonPropertyName("api_verno")]
public required string ApiVerno { get; set; }

[JsonPropertyName("api_preset_id")]
public required string ApiPresetId { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace ElectronicObserver.KancolleApi.Types.ApiReqKaisou.PresetSlotDelete;

/// <summary>
/// There's no response data.
/// </summary>
public class ApiReqKaisouPresetSlotDeleteResponse;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace ElectronicObserver.KancolleApi.Types.ApiReqKaisou.PresetSlotUpdateExslotFlag;

public class ApiReqKaisouPresetSlotUpdateExslotFlagRequest
{
[JsonPropertyName("api_token")]
public required string ApiToken { get; set; }

[JsonPropertyName("api_verno")]
public required string ApiVerno { get; set; }

[JsonPropertyName("api_preset_id")]
public required string ApiPresetId { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace ElectronicObserver.KancolleApi.Types.ApiReqKaisou.PresetSlotUpdateExslotFlag;

/// <summary>
/// There's no response data.
/// </summary>
public class ApiReqKaisouPresetSlotUpdateExslotFlagResponse;
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ public class ApiGetitem
[JsonPropertyName("api_mst_id")]
public int ApiMstId { get; set; }

/// <summary>
/// Element type is <see cref="Models.ApiSlotitem"/> or <see cref="List{T}"/> of <see cref="Models.ApiSlotitem"/>s.
/// </summary>
[JsonPropertyName("api_slotitem")]
public ApiSlotitem? ApiSlotitem { get; set; }
public object? ApiSlotitem { get; set; }

[JsonPropertyName("api_usemst")]
public int ApiUsemst { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ public class ApiPictureBookList
[JsonPropertyName("api_souk")]
public int ApiSouk { get; set; }

/// <summary>
/// Element type is <see cref="int"/> or <see cref="List{T}"/> of <see cref="int"/>s.
/// </summary>
[JsonPropertyName("api_state")]
public List<List<int>> ApiState { get; set; } = new();
public List<object> ApiState { get; set; } = new();

[JsonPropertyName("api_stype")]
public int? ApiStype { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
Jebzou marked this conversation as resolved.
Show resolved Hide resolved
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Web;
using CommunityToolkit.Mvvm.Input;
using ElectronicObserver.Database;
Expand All @@ -15,6 +17,10 @@ namespace ElectronicObserver.Window.Tools.DatabaseExplorer.ApiTypeTester;
public partial class ApiTypeTesterViewModel
{
private ElectronicObserverContext Db { get; } = new();
private JsonSerializerOptions Options { get; } = new()
{
UnmappedMemberHandling = JsonUnmappedMemberHandling.Skip,
};

public ObservableCollection<string> ParsingErrors { get; } = new();

Expand All @@ -32,12 +38,15 @@ private void Run()
switch (file.ApiFileType)
{
case ApiFileType.Request:
NameValueCollection query = HttpUtility.ParseQueryString(file.Content);
if (!file.Content.StartsWith('{'))
{
NameValueCollection query = HttpUtility.ParseQueryString(file.Content);

Dictionary<string, string> dictionary = query.AllKeys
.ToDictionary(k => k, k => query[k]);
Dictionary<string, string> dictionary = query.AllKeys
.ToDictionary(k => k, k => query[k]);

file.Content = JsonSerializer.Serialize(dictionary);
file.Content = JsonSerializer.Serialize(dictionary);
}

ParseRequest(file);
break;
Expand All @@ -60,33 +69,44 @@ private void ParseRequest(Database.KancolleApi.ApiFile file)
{
try
{
_ = file.GetRequestApiData();
_ = file.GetRequestApiData(Options);
}
catch (Exception e)
{
string error = $"{file.Name}: {e.Message}";

if (!ParsingErrors.Contains(error))
{
ParsingErrors.Add(error);
}
AddError(file, e);
}
}

private void ParseResponse(Database.KancolleApi.ApiFile file)
{
try
{
_ = file.GetResponseApiData();
_ = file.GetResponseApiData(Options);
}
catch (Exception e)
{
string error = $"{file.Name}: {e.Message}";
AddError(file, e);
}
}

if (!ParsingErrors.Contains(error))
{
ParsingErrors.Add(error);
}
private void AddError(Database.KancolleApi.ApiFile file, Exception e)
{
try
{
// ignore invalid json values
// can happen if there are connection issues
JsonDocument.Parse(file.Content);
}
catch
{
return;
}

string error = $"{file.TimeStamp} {file.ApiFileType} {file.Name}: {e.Message}";

if (!ParsingErrors.Contains(error))
{
ParsingErrors.Add(error);
}
}
}
Loading
Loading