From 6c2104f6d74b703cc78480728411885245557a81 Mon Sep 17 00:00:00 2001 From: Michael Shabanov Date: Sun, 23 Feb 2020 23:27:12 +0300 Subject: [PATCH] GraphQl dataStructure refactored --- .../PlayerAcchievementsInfoObjectType.cs | 6 + .../PlayerAccountInfoObjectType.cs | 13 +- .../ObjectTypes/PlayerClanInfoObjectType.cs | 6 + .../ObjectTypes/PlayerTankInfoObjectType.cs | 6 + .../Query/WotBlitzStatisticsQuery.cs | 139 +----------------- WotBlitzStatistics.GraphQl/Startup.cs | 11 +- .../WotBlitzStatistics.GraphQl.csproj | 1 - .../Model/AccountFullStatistics.cs | 7 +- 8 files changed, 35 insertions(+), 154 deletions(-) create mode 100644 WotBlitzStatistics.GraphQl/ObjectTypes/PlayerAcchievementsInfoObjectType.cs create mode 100644 WotBlitzStatistics.GraphQl/ObjectTypes/PlayerClanInfoObjectType.cs create mode 100644 WotBlitzStatistics.GraphQl/ObjectTypes/PlayerTankInfoObjectType.cs diff --git a/WotBlitzStatistics.GraphQl/ObjectTypes/PlayerAcchievementsInfoObjectType.cs b/WotBlitzStatistics.GraphQl/ObjectTypes/PlayerAcchievementsInfoObjectType.cs new file mode 100644 index 0000000..9aab088 --- /dev/null +++ b/WotBlitzStatistics.GraphQl/ObjectTypes/PlayerAcchievementsInfoObjectType.cs @@ -0,0 +1,6 @@ +namespace WotBlitzStatistics.GraphQl.ObjectTypes +{ + public class PlayerAcchievementsInfoObjectType + { + } +} diff --git a/WotBlitzStatistics.GraphQl/ObjectTypes/PlayerAccountInfoObjectType.cs b/WotBlitzStatistics.GraphQl/ObjectTypes/PlayerAccountInfoObjectType.cs index e2bbaa1..8b88641 100644 --- a/WotBlitzStatistics.GraphQl/ObjectTypes/PlayerAccountInfoObjectType.cs +++ b/WotBlitzStatistics.GraphQl/ObjectTypes/PlayerAccountInfoObjectType.cs @@ -1,17 +1,16 @@ using HotChocolate.Types; -using System; using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using WotBlitzStatisticsPro.Common.Model; +using WotBlitzStatisticsPro.WgApiClient.Model; namespace WotBlitzStatistics.GraphQl.ObjectTypes { - public class PlayerAccountInfoObjectType: ObjectType + public class PlayerAccountInfoObjectType: ObjectType { - protected override void Configure(IObjectTypeDescriptor descriptor) + protected override void Configure(IObjectTypeDescriptor descriptor) { - base.Configure(descriptor); + descriptor.Field(a => a.Private).Ignore(); + descriptor.Field("Tanks").Type>>() + .Resolver(c => new List { "Fuck yeah" }); // Add resolver for Clan, Tanks, Achievements // https://hotchocolate.io/docs/schema-object-type } diff --git a/WotBlitzStatistics.GraphQl/ObjectTypes/PlayerClanInfoObjectType.cs b/WotBlitzStatistics.GraphQl/ObjectTypes/PlayerClanInfoObjectType.cs new file mode 100644 index 0000000..4769d2c --- /dev/null +++ b/WotBlitzStatistics.GraphQl/ObjectTypes/PlayerClanInfoObjectType.cs @@ -0,0 +1,6 @@ +namespace WotBlitzStatistics.GraphQl.ObjectTypes +{ + public class PlayerClanInfoObjectType + { + } +} diff --git a/WotBlitzStatistics.GraphQl/ObjectTypes/PlayerTankInfoObjectType.cs b/WotBlitzStatistics.GraphQl/ObjectTypes/PlayerTankInfoObjectType.cs new file mode 100644 index 0000000..46eac39 --- /dev/null +++ b/WotBlitzStatistics.GraphQl/ObjectTypes/PlayerTankInfoObjectType.cs @@ -0,0 +1,6 @@ +namespace WotBlitzStatistics.GraphQl.ObjectTypes +{ + public class PlayerTankInfoObjectType + { + } +} diff --git a/WotBlitzStatistics.GraphQl/Query/WotBlitzStatisticsQuery.cs b/WotBlitzStatistics.GraphQl/Query/WotBlitzStatisticsQuery.cs index bf85160..e2511ea 100644 --- a/WotBlitzStatistics.GraphQl/Query/WotBlitzStatisticsQuery.cs +++ b/WotBlitzStatistics.GraphQl/Query/WotBlitzStatisticsQuery.cs @@ -1,7 +1,7 @@ using Newtonsoft.Json; using System.Threading.Tasks; -using WotBlitzStatisticsPro.Common.Model; using WotBlitzStatisticsPro.WgApiClient; +using WotBlitzStatisticsPro.WgApiClient.Model; namespace WotBlitzStatistics.GraphQl.Query { @@ -14,142 +14,9 @@ namespace WotBlitzStatistics.GraphQl.Query _wargamingApiClient = wargamingApiClient; } - public async Task GetPlayerInfo(long accountId) + public Task GetPlayerInfo(long accountId) { - var account = await _wargamingApiClient.GetPlayerAccountInfo(accountId); - // ToDo: think abount mappers or resolvers - var accountStub = JsonConvert.DeserializeObject(AccountJson); - accountStub.AccountId = accountId; - return accountStub; + return _wargamingApiClient.GetPlayerAccountInfo(accountId); } - - - private const string AccountJson = -@" -{ - ""AccountId"": 90277267, - ""NickName"": ""Mboga [XXX_L]"", - ""AccountCreatedAt"": ""2018-01-20T11:17:35+03:00"", - ""LastBattleTime"": ""2020-02-07T20:03:34+03:00"", - ""Battles"": 10842, - ""Wn7"": 1283.4155297487303, - ""AvgTier"": 7.364785095000922, - ""Winrate"": 54.75926950747095, - ""AvgDamage"": 1266.5282235749862, - ""AvgXp"": 663.4533296439771, - ""Achievements"": [ - { - ""AchievementId"": ""medalHalonen"", - ""Section"": ""epic"", - ""Name"": ""Halonen's Medal (medalHalonen)\r\nDestroy at least 3 enemy vehicles with a tank destroyer in one battle."", - ""Image"": ""http://glossary-ru-static.gcdn.co/icons/wotb/current/achievements/medalHalonen.png"", - ""Count"": 3 - }, - { - ""AchievementId"": ""medalLehvaslaiho"", - ""Section"": ""epic"", - ""Name"": ""Lehväslaiho's Medal (medalLehvaslaiho)\r\nDestroy 2 enemy vehicles with a medium tank in one battle."", - ""Image"": ""http://glossary-ru-static.gcdn.co/icons/wotb/current/achievements/medalLehvaslaiho.png"", - ""Count"": 47 - }, - { - ""AchievementId"": ""markOfMastery"", - ""Section"": ""battle"", - ""Name"": ""Mastery badge: \nAce Tanker (markOfMastery)\r\nProve your mastery in controlling a vehicle. Earn more XP in a battle than the average highest XP of 99% of players who have fought in this vehicle for the previous 7 days."", - ""Image"": ""http://glossary-ru-static.gcdn.co/icons/wotb/current/achievements/markOfMastery.png"", - ""Count"": 73 - }, - { - ""AchievementId"": ""medalKolobanov"", - ""Section"": ""epic"", - ""Name"": ""Kolobanov's Medal (medalKolobanov)\r\nStand alone against 3 enemy vehicles and win."", - ""Image"": ""http://glossary-ru-static.gcdn.co/icons/wotb/current/achievements/medalKolobanov.png"", - ""Count"": 6 - }, - { - ""AchievementId"": ""medalLafayettePool"", - ""Section"": ""epic"", - ""Name"": ""Pool's Medal (medalLafayettePool)\r\nDestroy 6 enemy vehicles in one battle."", - ""Image"": ""http://glossary-ru-static.gcdn.co/icons/wotb/current/achievements/medalLafayettePool.png"", - ""Count"": 7 - }, - { - ""AchievementId"": ""medalOrlik"", - ""Section"": ""epic"", - ""Name"": ""Orlik's Medal (medalOrlik)\r\nDestroy at least 3 enemy vehicles with a light tank in one battle."", - ""Image"": ""http://glossary-ru-static.gcdn.co/icons/wotb/current/achievements/medalOrlik.png"", - ""Count"": 4 - }, - { - ""AchievementId"": ""medalRadleyWalters"", - ""Section"": ""epic"", - ""Name"": ""Radley-Walters's Medal (medalRadleyWalters)\r\nDestroy 5 enemy vehicles in one battle."", - ""Image"": ""http://glossary-ru-static.gcdn.co/icons/wotb/current/achievements/medalRadleyWalters.png"", - ""Count"": 33 - }, - { - ""AchievementId"": ""medalOskin"", - ""Section"": ""epic"", - ""Name"": ""Oskin's Medal (medalOskin)\r\nDestroy 3 enemy vehicles with a medium tank in one battle."", - ""Image"": ""http://glossary-ru-static.gcdn.co/icons/wotb/current/achievements/medalOskin.png"", - ""Count"": 6 - }, - { - ""AchievementId"": ""medalNikolas"", - ""Section"": ""epic"", - ""Name"": ""Nicols's Medal (medalNikolas)\r\nDestroy at least 4 enemy vehicles with a medium tank in one battle."", - ""Image"": ""http://glossary-ru-static.gcdn.co/icons/wotb/current/achievements/medalNikolas.png"", - ""Count"": 1 - } - ], - ""TopTanks"": [ - { - ""TankId"": 59905, - ""MarkOfMastery"": 4, - ""Battles"": 769, - ""WinRate"": 57.737321196358907672301690507, - ""AvgDamage"": 1378.6579973992197659297789337, - ""AvgXp"": 764.92847854356306892067620286, - ""Name"": ""T-54 first prototype"", - ""Tier"": 8, - ""TierRoman"": ""VIII"", - ""Nation"": ""ussr"", - ""Type"": ""mediumTank"", - ""IsPremium"": true, - ""PreviewImageUrl"": ""http://glossary-ru-static.gcdn.co/icons/wotb/current/uploaded/vehicles/hd_thumbnail/R112_T54_45.png"" - }, - { - ""TankId"": 13345, - ""MarkOfMastery"": 4, - ""Battles"": 662, - ""WinRate"": 55.287009063444108761329305136, - ""AvgDamage"": 1344.1555891238670694864048338, - ""AvgXp"": 776.1495468277945619335347432, - ""Name"": ""T26E4 SuperPershing"", - ""Tier"": 8, - ""TierRoman"": ""VIII"", - ""Nation"": ""usa"", - ""Type"": ""mediumTank"", - ""IsPremium"": true, - ""PreviewImageUrl"": ""http://glossary-ru-static.gcdn.co/icons/wotb/current/uploaded/vehicles/hd_thumbnail/T26_E4_SuperPershing.png"" - }, - { - ""TankId"": 9217, - ""MarkOfMastery"": 4, - ""Battles"": 439, - ""WinRate"": 55.808656036446469248291571754, - ""AvgDamage"": 1493.7220956719817767653758542, - ""AvgXp"": 737.12072892938496583143507973, - ""Name"": ""IS-6"", - ""Tier"": 8, - ""TierRoman"": ""VIII"", - ""Nation"": ""ussr"", - ""Type"": ""heavyTank"", - ""IsPremium"": true, - ""PreviewImageUrl"": ""http://glossary-ru-static.gcdn.co/icons/wotb/current/uploaded/vehicles/hd_thumbnail/Object252.png"" - } - ] -} -"; } } diff --git a/WotBlitzStatistics.GraphQl/Startup.cs b/WotBlitzStatistics.GraphQl/Startup.cs index f156b08..1d08734 100644 --- a/WotBlitzStatistics.GraphQl/Startup.cs +++ b/WotBlitzStatistics.GraphQl/Startup.cs @@ -5,9 +5,10 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using WotBlitzStatistics.GraphQl.ObjectTypes; using WotBlitzStatistics.GraphQl.Query; -using WotBlitzStatisticsPro.Common.Model; using WotBlitzStatisticsPro.WgApiClient; +using WotBlitzStatisticsPro.WgApiClient.Model; namespace WotBlitzStatistics.GraphQl { @@ -40,10 +41,10 @@ namespace WotBlitzStatistics.GraphQl .AddQueryType() //.AddMutationType() //.AddSubscriptionType() - .AddType() - .AddType() - .AddType() - .AddEnumType() + .AddType() + .AddType() + .AddType() + //.AddEnumType() .Create()); } diff --git a/WotBlitzStatistics.GraphQl/WotBlitzStatistics.GraphQl.csproj b/WotBlitzStatistics.GraphQl/WotBlitzStatistics.GraphQl.csproj index 406889a..0ae6de8 100644 --- a/WotBlitzStatistics.GraphQl/WotBlitzStatistics.GraphQl.csproj +++ b/WotBlitzStatistics.GraphQl/WotBlitzStatistics.GraphQl.csproj @@ -13,7 +13,6 @@ - diff --git a/WotBlitzStatisticsPro.WgApiClient/Model/AccountFullStatistics.cs b/WotBlitzStatisticsPro.WgApiClient/Model/AccountFullStatistics.cs index a9dd062..ead9c28 100644 --- a/WotBlitzStatisticsPro.WgApiClient/Model/AccountFullStatistics.cs +++ b/WotBlitzStatisticsPro.WgApiClient/Model/AccountFullStatistics.cs @@ -1,7 +1,4 @@ using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Text; namespace WotBlitzStatisticsPro.WgApiClient.Model { @@ -86,13 +83,13 @@ namespace WotBlitzStatisticsPro.WgApiClient.Model public long? MaxXpTankId { get; set; } /// - /// Totla shots count + /// Total shots count /// [JsonProperty("shots")] public long? Shots { get; set; } /// - /// Totla count of spotted vehicles + /// Total count of spotted vehicles /// [JsonProperty("spotted")] public long? Spotted { get; set; }