Added GraphQl Server and wg API client

This commit is contained in:
Michael Shabanov committed 2020-02-15 16:00:42 +03:00
1 parent a0ad7ca395
commit abc99c835c
25 files changed
+872 -1

No files matched your search

@@ -0,0 +1,19 @@
using HotChocolate.Types;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WotBlitzStatisticsPro.Common.Model;
namespace WotBlitzStatistics.GraphQl.ObjectTypes
{
public class PlayerAccountInfoObjectType: ObjectType<PlayerAccountInfo>
{
protected override void Configure(IObjectTypeDescriptor<PlayerAccountInfo> descriptor)
{
base.Configure(descriptor);
// Add resolver for Clan, Tanks, Achievements
// https://hotchocolate.io/docs/schema-object-type
}
}
}
+26
View File
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace WotBlitzStatistics.GraphQl
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
@@ -0,0 +1,30 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:63522",
"sslPort": 44333
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "graphql/playground",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"WotBlitzStatistics.GraphQl": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "graphql/playground",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
@@ -0,0 +1,155 @@
using Newtonsoft.Json;
using System.Threading.Tasks;
using WotBlitzStatisticsPro.Common.Model;
using WotBlitzStatisticsPro.WgApiClient;
namespace WotBlitzStatistics.GraphQl.Query
{
public class WotBlitzStatisticsQuery
{
private readonly IWargamingApiClient _wargamingApiClient;
public WotBlitzStatisticsQuery(IWargamingApiClient wargamingApiClient)
{
_wargamingApiClient = wargamingApiClient;
}
public async Task<PlayerAccountInfo> GetPlayerInfo(long accountId)
{
var account = await _wargamingApiClient.GetPlayerAccountInfo(accountId);
// ToDo: think abount mappers or resolvers
var accountStub = JsonConvert.DeserializeObject<PlayerAccountInfo>(AccountJson);
accountStub.AccountId = accountId;
return accountStub;
}
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""
}
]
}
";
}
}
+59
View File
@@ -0,0 +1,59 @@
using HotChocolate;
using HotChocolate.AspNetCore;
using HotChocolate.AspNetCore.Voyager;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using WotBlitzStatistics.GraphQl.Query;
using WotBlitzStatisticsPro.Common.Model;
using WotBlitzStatisticsPro.WgApiClient;
namespace WotBlitzStatistics.GraphQl
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
var wgApiConfig = new WargamingApiSettings();
Configuration.GetSection("WargamingApi").Bind(wgApiConfig);
services.AddSingleton<IWargamingApiSettings>(wgApiConfig);
services.AddHttpClient<IWargamingApiClient, WargamingApiClient>();
// Add GraphQL Services
services.AddGraphQL(sp => SchemaBuilder.New()
.AddServices(sp)
// Adds the authorize directive and
// enable the authorization middleware.
.AddAuthorizeDirectiveType()
.AddQueryType<WotBlitzStatisticsQueryType>()
//.AddMutationType<MutationType>()
//.AddSubscriptionType<SubscriptionType>()
.AddType<PlayerAccountInfo>()
.AddType<PlayerAchievementInfo>()
.AddType<PlayerTankInfo>()
.AddEnumType<MarkOfMastery>()
.Create());
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app
.UseGraphQL("/graphql")
.UsePlayground("/graphql")
.UseVoyager("/graphql")
;
}
}
}
@@ -0,0 +1,9 @@
using WotBlitzStatisticsPro.WgApiClient;
namespace WotBlitzStatistics.GraphQl
{
public class WargamingApiSettings : IWargamingApiSettings
{
public string ApplicationId { get; set; }
}
}
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="HotChocolate.AspNetCore" Version="10.3.5" />
<PackageReference Include="HotChocolate.AspNetCore.Authorization" Version="10.3.5" />
<PackageReference Include="HotChocolate.AspNetCore.Playground" Version="10.3.5" />
<PackageReference Include="HotChocolate.AspNetCore.Voyager" Version="10.3.5" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WotBlitzStatisticsPro.Common\WotBlitzStatisticsPro.Common.csproj" />
<ProjectReference Include="..\WotBlitzStatisticsPro.WgApiClient\WotBlitzStatisticsPro.WgApiClient.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
@@ -0,0 +1,14 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"WargamingApi": {
"ApplicationId": "e6bb7a6cd1b7da3ca5697f97072d2176"
}
}