mirror of
https://github.com/DrMboga/WotBlitzStatisticsBlazor.git
synced 2026-10-21 02:17:20 +02:00
Rethinking the API
This commit is contained in:
1 parent
83628d21bd
commit
a4b3ae96fd
11 files changed
+127
-16
No files matched your search
@@ -0,0 +1,10 @@
|
||||
using HotChocolate.Types;
|
||||
using WotBlitzStatisticsPro.Common.Model;
|
||||
|
||||
namespace WotBlitzStatistics.GraphQl.ObjectTypes
|
||||
{
|
||||
public class AccountsSearchItemObjectType: ObjectType<AccountsSearchResponseItem>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using HotChocolate.Types;
|
||||
using HotChocolate.Types.Relay;
|
||||
using WotBlitzStatisticsPro.Common.Model;
|
||||
|
||||
namespace WotBlitzStatistics.GraphQl.ObjectTypes
|
||||
{
|
||||
public class AccountsSearchObjectType: ObjectType<AccountsSearchResponse>
|
||||
{
|
||||
// ToDo: This is just for history. We don't need to paginate this because each page request does the request to API.
|
||||
// The database driver can optimize this and will request data page by page
|
||||
|
||||
//protected override void Configure(IObjectTypeDescriptor<AccountsSearchResponse> descriptor)
|
||||
//{
|
||||
// descriptor.Field(r => r.Accounts)
|
||||
// .UsePaging<AccountsSearchItemObjectType>();
|
||||
//}
|
||||
|
||||
/*
|
||||
Paging request example
|
||||
query($accountSearchNick: String!) {
|
||||
findAccounts(accountNick: $accountSearchNick) {
|
||||
accounts(first: 5, after: "eyJfX3RvdGFsQ291bnQiOjc0LCJfX3Bvc2l0aW9uIjo5fQ==") {
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
hasPreviousPage
|
||||
startCursor
|
||||
endCursor
|
||||
}
|
||||
totalCount
|
||||
nodes {
|
||||
accountId
|
||||
nickname
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using WotBlitzStatisticsPro.Common.Model;
|
||||
using WotBlitzStatisticsPro.WgApiClient;
|
||||
using WotBlitzStatisticsPro.WgApiClient.Model;
|
||||
|
||||
namespace WotBlitzStatistics.GraphQl.Query
|
||||
{
|
||||
@@ -14,9 +14,22 @@ namespace WotBlitzStatistics.GraphQl.Query
|
||||
_wargamingApiClient = wargamingApiClient;
|
||||
}
|
||||
|
||||
public Task<AccountInfo> GetPlayerInfo(long accountId)
|
||||
//public Task<AccountInfo> GetPlayerInfo(long accountId)
|
||||
//{
|
||||
// return _wargamingApiClient.GetPlayerAccountInfo(accountId);
|
||||
//}
|
||||
|
||||
public async Task<AccountsSearchResponse> FindAccounts(string accountNick)
|
||||
{
|
||||
return _wargamingApiClient.GetPlayerAccountInfo(accountId);
|
||||
var response = await _wargamingApiClient.FindAccounts(accountNick);
|
||||
// ToDo: Use auto mapper
|
||||
var result = new AccountsSearchResponse
|
||||
{
|
||||
AccountsCount = response.Count,
|
||||
Accounts = new List<AccountsSearchResponseItem>()
|
||||
};
|
||||
response.ForEach(r => result.Accounts.Add(new AccountsSearchResponseItem {AccountId = r.AccountId.Value, Nickname = r.Nickname}));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,9 @@ namespace WotBlitzStatistics.GraphQl
|
||||
services.AddHttpClient<IWargamingApiClient, WargamingApiClient>();
|
||||
|
||||
// Global data loader - caches data between requests
|
||||
// ToDo: cause nullreference exception
|
||||
//services.AddSingleton<IDataLoaderRegistry, DataLoaderRegistry>();
|
||||
|
||||
// this enables you to use DataLoader in your resolvers.
|
||||
services.AddDataLoaderRegistry();
|
||||
|
||||
@@ -47,11 +49,8 @@ namespace WotBlitzStatistics.GraphQl
|
||||
.AddQueryType<WotBlitzStatisticsQuery>()
|
||||
//.AddMutationType<MutationType>()
|
||||
//.AddSubscriptionType<SubscriptionType>()
|
||||
.AddType<PlayerAccountInfoObjectType>()
|
||||
.AddType<AccountStatistics>()
|
||||
.AddType<AccountFullStatistics>()
|
||||
.AddType<PlayerClanInfoObjectType>()
|
||||
.AddType<ClanInfoObjectType>()
|
||||
.AddType<AccountsSearchItemObjectType>()
|
||||
.AddType<AccountsSearchObjectType>()
|
||||
//.AddEnumType<MarkOfMastery>()
|
||||
.Create());
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\WotBlitzStatisticsPro.Common\WotBlitzStatisticsPro.Common.csproj" />
|
||||
<ProjectReference Include="..\WotBlitzStatisticsPro.WgApiClient\WotBlitzStatisticsPro.WgApiClient.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace WotBlitzStatisticsPro.Common.Model
|
||||
{
|
||||
public class AccountsSearchResponse
|
||||
{
|
||||
public int AccountsCount { get; set; }
|
||||
public ICollection<AccountsSearchResponseItem> Accounts { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace WotBlitzStatisticsPro.Common.Model
|
||||
{
|
||||
public class AccountsSearchResponseItem
|
||||
{
|
||||
///<summary>
|
||||
/// Player accountId
|
||||
///</summary>
|
||||
public long AccountId { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Player nick
|
||||
///</summary>
|
||||
public string Nickname { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using System.Text;
|
||||
|
||||
namespace WotBlitzStatisticsPro.Common.Model
|
||||
{
|
||||
[Obsolete("Use AccountsSearchResponse instead")]
|
||||
public class AccountsSearchResult
|
||||
{
|
||||
public int TotalAccountsCount { get; set; }
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace WotBlitzStatisticsPro.WgApiClient
|
||||
{
|
||||
public interface IWargamingApiClient
|
||||
{
|
||||
Task<Dictionary<long, string>> FindAccounts(string nickName,
|
||||
Task<List<WotAccountListResponse>> FindAccounts(string nickName,
|
||||
RealmType realmType = RealmType.Ru,
|
||||
RequestLanguage language = RequestLanguage.En);
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace WotBlitzStatisticsPro.WgApiClient.Model
|
||||
{
|
||||
public class WotAccountListResponse
|
||||
{
|
||||
///<summary>
|
||||
/// Player accountId
|
||||
///</summary>
|
||||
[JsonProperty("account_id")]
|
||||
public long? AccountId { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Player nick
|
||||
///</summary>
|
||||
[JsonProperty("nickname")]
|
||||
public string Nickname { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using WotBlitzStatisticsPro.WgApiClient.Model;
|
||||
@@ -8,19 +7,24 @@ namespace WotBlitzStatisticsPro.WgApiClient
|
||||
{
|
||||
public class WargamingApiClient : WagramingApiClientBase, IWargamingApiClient
|
||||
{
|
||||
// ToDo: AddLogging
|
||||
public WargamingApiClient(
|
||||
HttpClient httpClient,
|
||||
IWargamingApiSettings wargamingApiSettings) : base(httpClient, wargamingApiSettings)
|
||||
{
|
||||
}
|
||||
|
||||
public Task<Dictionary<long, string>> FindAccounts(string nickName,
|
||||
public async Task<List<WotAccountListResponse>> FindAccounts(string nickName,
|
||||
RealmType realmType = RealmType.Ru,
|
||||
RequestLanguage language = RequestLanguage.En)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
return await GetFromBlitzApi<List<WotAccountListResponse>>(
|
||||
realmType,
|
||||
language,
|
||||
"account/list/",
|
||||
$"search={nickName}").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// https://api.wotblitz.ru/wotb/clans/list/?application_id=adc1387489cf9fc8d9a1d85dbd27763d&search=xxx
|
||||
|
||||
public async Task<AccountInfo> GetPlayerAccountInfo(long accountId,
|
||||
RealmType realmType = RealmType.Ru,
|
||||
|
||||
Reference in new issue
Block a user