diff --git a/WotBlitzStatistics.GraphQl/ObjectTypes/AccountsSearchItemObjectType.cs b/WotBlitzStatistics.GraphQl/ObjectTypes/AccountsSearchItemObjectType.cs new file mode 100644 index 0000000..fc9096d --- /dev/null +++ b/WotBlitzStatistics.GraphQl/ObjectTypes/AccountsSearchItemObjectType.cs @@ -0,0 +1,10 @@ +using HotChocolate.Types; +using WotBlitzStatisticsPro.Common.Model; + +namespace WotBlitzStatistics.GraphQl.ObjectTypes +{ + public class AccountsSearchItemObjectType: ObjectType + { + + } +} \ No newline at end of file diff --git a/WotBlitzStatistics.GraphQl/ObjectTypes/AccountsSearchObjectType.cs b/WotBlitzStatistics.GraphQl/ObjectTypes/AccountsSearchObjectType.cs new file mode 100644 index 0000000..f60f66b --- /dev/null +++ b/WotBlitzStatistics.GraphQl/ObjectTypes/AccountsSearchObjectType.cs @@ -0,0 +1,39 @@ +using HotChocolate.Types; +using HotChocolate.Types.Relay; +using WotBlitzStatisticsPro.Common.Model; + +namespace WotBlitzStatistics.GraphQl.ObjectTypes +{ + public class AccountsSearchObjectType: ObjectType + { + // 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 descriptor) + //{ + // descriptor.Field(r => r.Accounts) + // .UsePaging(); + //} + + /* + Paging request example +query($accountSearchNick: String!) { + findAccounts(accountNick: $accountSearchNick) { + accounts(first: 5, after: "eyJfX3RvdGFsQ291bnQiOjc0LCJfX3Bvc2l0aW9uIjo5fQ==") { + pageInfo { + hasNextPage + hasPreviousPage + startCursor + endCursor + } + totalCount + nodes { + accountId + nickname + } + } + } +} + */ + } +} \ No newline at end of file diff --git a/WotBlitzStatistics.GraphQl/Query/WotBlitzStatisticsQuery.cs b/WotBlitzStatistics.GraphQl/Query/WotBlitzStatisticsQuery.cs index e2511ea..7a6107b 100644 --- a/WotBlitzStatistics.GraphQl/Query/WotBlitzStatisticsQuery.cs +++ b/WotBlitzStatistics.GraphQl/Query/WotBlitzStatisticsQuery.cs @@ -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 GetPlayerInfo(long accountId) + //public Task GetPlayerInfo(long accountId) + //{ + // return _wargamingApiClient.GetPlayerAccountInfo(accountId); + //} + + public async Task 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() + }; + response.ForEach(r => result.Accounts.Add(new AccountsSearchResponseItem {AccountId = r.AccountId.Value, Nickname = r.Nickname})); + return result; } } } diff --git a/WotBlitzStatistics.GraphQl/Startup.cs b/WotBlitzStatistics.GraphQl/Startup.cs index 96105e0..2f98cee 100644 --- a/WotBlitzStatistics.GraphQl/Startup.cs +++ b/WotBlitzStatistics.GraphQl/Startup.cs @@ -32,7 +32,9 @@ namespace WotBlitzStatistics.GraphQl services.AddHttpClient(); // Global data loader - caches data between requests + // ToDo: cause nullreference exception //services.AddSingleton(); + // this enables you to use DataLoader in your resolvers. services.AddDataLoaderRegistry(); @@ -47,11 +49,8 @@ namespace WotBlitzStatistics.GraphQl .AddQueryType() //.AddMutationType() //.AddSubscriptionType() - .AddType() - .AddType() - .AddType() - .AddType() - .AddType() + .AddType() + .AddType() //.AddEnumType() .Create()); } diff --git a/WotBlitzStatistics.GraphQl/WotBlitzStatistics.GraphQl.csproj b/WotBlitzStatistics.GraphQl/WotBlitzStatistics.GraphQl.csproj index b55e7bc..4ad9797 100644 --- a/WotBlitzStatistics.GraphQl/WotBlitzStatistics.GraphQl.csproj +++ b/WotBlitzStatistics.GraphQl/WotBlitzStatistics.GraphQl.csproj @@ -15,6 +15,7 @@ + diff --git a/WotBlitzStatisticsPro.Common/Model/AccountsSearchResponse.cs b/WotBlitzStatisticsPro.Common/Model/AccountsSearchResponse.cs new file mode 100644 index 0000000..6163799 --- /dev/null +++ b/WotBlitzStatisticsPro.Common/Model/AccountsSearchResponse.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; + +namespace WotBlitzStatisticsPro.Common.Model +{ + public class AccountsSearchResponse + { + public int AccountsCount { get; set; } + public ICollection Accounts { get; set; } + } +} \ No newline at end of file diff --git a/WotBlitzStatisticsPro.Common/Model/AccountsSearchResponseItem.cs b/WotBlitzStatisticsPro.Common/Model/AccountsSearchResponseItem.cs new file mode 100644 index 0000000..482a6bc --- /dev/null +++ b/WotBlitzStatisticsPro.Common/Model/AccountsSearchResponseItem.cs @@ -0,0 +1,15 @@ +namespace WotBlitzStatisticsPro.Common.Model +{ + public class AccountsSearchResponseItem + { + /// + /// Player accountId + /// + public long AccountId { get; set; } + + /// + /// Player nick + /// + public string Nickname { get; set; } + } +} \ No newline at end of file diff --git a/WotBlitzStatisticsPro.Common/Model/AccountsSearchResult.cs b/WotBlitzStatisticsPro.Common/Model/AccountsSearchResult.cs index 4dc16d6..1891514 100644 --- a/WotBlitzStatisticsPro.Common/Model/AccountsSearchResult.cs +++ b/WotBlitzStatisticsPro.Common/Model/AccountsSearchResult.cs @@ -4,6 +4,7 @@ using System.Text; namespace WotBlitzStatisticsPro.Common.Model { + [Obsolete("Use AccountsSearchResponse instead")] public class AccountsSearchResult { public int TotalAccountsCount { get; set; } diff --git a/WotBlitzStatisticsPro.WgApiClient/IWargamingApiClient.cs b/WotBlitzStatisticsPro.WgApiClient/IWargamingApiClient.cs index c9863a5..52cf08a 100644 --- a/WotBlitzStatisticsPro.WgApiClient/IWargamingApiClient.cs +++ b/WotBlitzStatisticsPro.WgApiClient/IWargamingApiClient.cs @@ -6,7 +6,7 @@ namespace WotBlitzStatisticsPro.WgApiClient { public interface IWargamingApiClient { - Task> FindAccounts(string nickName, + Task> FindAccounts(string nickName, RealmType realmType = RealmType.Ru, RequestLanguage language = RequestLanguage.En); diff --git a/WotBlitzStatisticsPro.WgApiClient/Model/WotAccountListResponse.cs b/WotBlitzStatisticsPro.WgApiClient/Model/WotAccountListResponse.cs new file mode 100644 index 0000000..4eb886e --- /dev/null +++ b/WotBlitzStatisticsPro.WgApiClient/Model/WotAccountListResponse.cs @@ -0,0 +1,19 @@ +using Newtonsoft.Json; + +namespace WotBlitzStatisticsPro.WgApiClient.Model +{ + public class WotAccountListResponse + { + /// + /// Player accountId + /// + [JsonProperty("account_id")] + public long? AccountId { get; set; } + + /// + /// Player nick + /// + [JsonProperty("nickname")] + public string Nickname { get; set; } + } +} \ No newline at end of file diff --git a/WotBlitzStatisticsPro.WgApiClient/WargamingApiClient.cs b/WotBlitzStatisticsPro.WgApiClient/WargamingApiClient.cs index 4d15697..fb848ff 100644 --- a/WotBlitzStatisticsPro.WgApiClient/WargamingApiClient.cs +++ b/WotBlitzStatisticsPro.WgApiClient/WargamingApiClient.cs @@ -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> FindAccounts(string nickName, + public async Task> FindAccounts(string nickName, RealmType realmType = RealmType.Ru, RequestLanguage language = RequestLanguage.En) { - throw new NotImplementedException(); - } + return await GetFromBlitzApi>( + realmType, + language, + "account/list/", + $"search={nickName}").ConfigureAwait(false); + } + + // https://api.wotblitz.ru/wotb/clans/list/?application_id=adc1387489cf9fc8d9a1d85dbd27763d&search=xxx public async Task GetPlayerAccountInfo(long accountId, RealmType realmType = RealmType.Ru,