mirror of
https://github.com/DrMboga/WotBlitzStatisticsBlazor.git
synced 2026-10-23 19:30:06 +02:00
313 files changed
+304310
-751
No files matched your search
@@ -1,42 +0,0 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using HotChocolate.Language;
|
||||
using WotBlitzStatisticsPro.Common.Model;
|
||||
|
||||
namespace WotBlitzStatisticsPro.GraphQl.Helpers
|
||||
{
|
||||
public static class ParametersParser
|
||||
{
|
||||
private const RealmType DefaultRealm = RealmType.Ru;
|
||||
private const RequestLanguage DefaultRequestLanguage = RequestLanguage.En;
|
||||
|
||||
public static RealmAndLanguage ParseOperation(this OperationDefinitionNode operationDefinition)
|
||||
{
|
||||
var realm = DefaultRealm;
|
||||
var language = DefaultRequestLanguage;
|
||||
var selections = operationDefinition?.SelectionSet.Selections.ToArray();
|
||||
if (selections != null && selections.Length == 1)
|
||||
{
|
||||
var node = selections[0] as FieldNode;
|
||||
if (node?.Arguments != null)
|
||||
{
|
||||
foreach (var argument in node.Arguments.Where(a => a != null))
|
||||
{
|
||||
switch (argument.Name.Value)
|
||||
{
|
||||
case "realmType" when argument?.Value?.Value != null:
|
||||
realm = (RealmType)Enum.Parse(typeof(RealmType), argument.Value.Value.ToString() ?? "Ru", true);
|
||||
break;
|
||||
case "requestLanguage" when argument?.Value?.Value != null:
|
||||
language = (RequestLanguage)Enum.Parse(typeof(RequestLanguage), argument.Value.Value.ToString() ?? "En", true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new (realm, language);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using HotChocolate.Types;
|
||||
using System.Threading.Tasks;
|
||||
using WotBlitzStatisticsPro.Common.Model;
|
||||
using WotBlitzStatisticsPro.WgApiClient;
|
||||
|
||||
namespace WotBlitzStatisticsPro.GraphQl.Mutation
|
||||
{
|
||||
[ExtendObjectType(Name = "Mutation")]
|
||||
public class WargamingAuthMutation
|
||||
{
|
||||
private readonly IWargamingAuthenticationClient _wargamingAuthenticationClient;
|
||||
|
||||
public WargamingAuthMutation(IWargamingAuthenticationClient wargamingAuthenticationClient)
|
||||
{
|
||||
_wargamingAuthenticationClient = wargamingAuthenticationClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prolongates Wargaming authentication token
|
||||
/// </summary>
|
||||
/// <param name="realm">Wargaming realm</param>
|
||||
/// <param name="oldToken">Old token to prolongate</param>
|
||||
/// <returns></returns>
|
||||
public Task<WargamingProlongInfo> ProlongAuthToken(RealmType realm, string oldToken)
|
||||
{
|
||||
return _wargamingAuthenticationClient.ProlongAuthToken(realm, oldToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes player's access token
|
||||
/// </summary>
|
||||
/// <param name="realm">Wargaming realm</param>
|
||||
/// <param name="token">Token to logout</param>
|
||||
/// <returns>Operation result</returns>
|
||||
public async Task<string> Logout(RealmType realm, string token)
|
||||
{
|
||||
await _wargamingAuthenticationClient.Logout(realm, token);
|
||||
return "OK";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes player's acoount history from database
|
||||
/// </summary>
|
||||
/// <param name="realm">Wargaming realm</param>
|
||||
/// <param name="accountId">Player Id</param>
|
||||
/// <returns>Operation result</returns>
|
||||
public Task<string> RemovePlayerHistory(RealmType realm, long accountId)
|
||||
{
|
||||
return Task.FromResult("Metod is not implemented yet.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using HotChocolate;
|
||||
using HotChocolate.AspNetCore.Authorization;
|
||||
using HotChocolate.Types;
|
||||
@@ -43,7 +44,7 @@ namespace WotBlitzStatisticsPro.GraphQl.Mutation
|
||||
/// <param name="requestLanguage">Request language</param>
|
||||
/// <param name="wgToken">Wargaming authentication token</param>
|
||||
/// <returns></returns>
|
||||
public Task<AccountInfoResponse> GatherAccountInformation(
|
||||
public Task<DateTime> GatherAccountInformation(
|
||||
RealmType realmType,
|
||||
long accountId,
|
||||
RequestLanguage requestLanguage,
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
using HotChocolate.Types;
|
||||
using WotBlitzStatisticsPro.Common.Model;
|
||||
|
||||
namespace WotBlitzStatisticsPro.GraphQl.ObjectTypes
|
||||
{
|
||||
[ExtendObjectType(Name = "Query")]
|
||||
public class StatisticsResponseType: InterfaceType<IStatisticsResponse>
|
||||
{
|
||||
protected override void Configure(IInterfaceTypeDescriptor<IStatisticsResponse> descriptor)
|
||||
{
|
||||
descriptor.Name("Statistics");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using HotChocolate.Types;
|
||||
using WotBlitzStatisticsPro.Common.Model;
|
||||
|
||||
namespace WotBlitzStatisticsPro.GraphQl.ObjectTypes
|
||||
{
|
||||
[ExtendObjectType(Name = "Query")]
|
||||
public class TankInfoResponseType: ObjectType<TankInfoResponse>
|
||||
{
|
||||
protected override void Configure(IObjectTypeDescriptor<TankInfoResponse> descriptor)
|
||||
{
|
||||
descriptor.Name("TankInfoResponse");
|
||||
descriptor.Implements<StatisticsResponseType>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,9 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Serilog;
|
||||
|
||||
namespace WotBlitzStatisticsPro.GraphQl
|
||||
{
|
||||
@@ -7,12 +11,36 @@ namespace WotBlitzStatisticsPro.GraphQl
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
CreateHostBuilder(args).Build().Run();
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("appsettings.json")
|
||||
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
|
||||
.AddEnvironmentVariables()
|
||||
.Build();
|
||||
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.ReadFrom.Configuration(configuration)
|
||||
.CreateLogger();
|
||||
|
||||
try
|
||||
{
|
||||
Log.Information("Starting web host");
|
||||
CreateHostBuilder(args).Build().Run();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Fatal(ex, "Host terminated unexpectedly");
|
||||
}
|
||||
finally
|
||||
{
|
||||
Log.CloseAndFlush();
|
||||
}
|
||||
}
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args)
|
||||
.ConfigureWebHostDefaults(webBuilder =>
|
||||
.UseSerilog()
|
||||
.ConfigureWebHostDefaults(webBuilder =>
|
||||
{
|
||||
webBuilder.UseStartup<Startup>();
|
||||
});
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
using HotChocolate.Types;
|
||||
using System.Threading.Tasks;
|
||||
using WotBlitzStatisticsPro.Common.Model;
|
||||
using WotBlitzStatisticsPro.WgApiClient;
|
||||
|
||||
namespace WotBlitzStatisticsPro.GraphQl.Query
|
||||
{
|
||||
[ExtendObjectType(Name = "Query")]
|
||||
public class WargamingAuthQuery
|
||||
{
|
||||
private readonly IWargamingAuthenticationClient _wargamingAuthenticationClient;
|
||||
|
||||
public WargamingAuthQuery(IWargamingAuthenticationClient wargamingAuthenticationClient)
|
||||
{
|
||||
_wargamingAuthenticationClient = wargamingAuthenticationClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns authentication URL accourding Realm
|
||||
/// </summary>
|
||||
/// <param name="realmType">Wargaming Realm.</param>
|
||||
/// <returns></returns>
|
||||
public string LoginUrl(RealmType realmType)
|
||||
{
|
||||
return _wargamingAuthenticationClient.LoginUrl(realmType);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ namespace WotBlitzStatisticsPro.GraphQl.Query
|
||||
/// <param name="realmType">Account region</param>
|
||||
/// <param name="accountId">AccountId</param>
|
||||
/// <param name="requestLanguage">Request language</param>
|
||||
public Task<AccountAchievementsResponse> GetAccountAchievements(
|
||||
public Task<AccountAchievementsResponse> AccountMedals(
|
||||
long accountId,
|
||||
RealmType? realmType,
|
||||
RequestLanguage? requestLanguage)
|
||||
@@ -36,7 +36,7 @@ namespace WotBlitzStatisticsPro.GraphQl.Query
|
||||
/// <param name="realmType">Account region</param>
|
||||
/// <param name="accountId">AccountId</param>
|
||||
/// <param name="requestLanguage">Request language</param>
|
||||
public Task<AccountAchievementsResponse> GetTankAchievements(
|
||||
public Task<AccountAchievementsResponse> TankMedals(
|
||||
long accountId,
|
||||
long tankId,
|
||||
RealmType? realmType,
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using HotChocolate.Types;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using WotBlitzStatisticsPro.Common.Model;
|
||||
using WotBlitzStatisticsPro.Logic;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using HotChocolate.Types;
|
||||
using WotBlitzStatisticsPro.Common.Model;
|
||||
using WotBlitzStatisticsPro.GraphQl.Helpers;
|
||||
using WotBlitzStatisticsPro.GraphQl.ObjectTypes;
|
||||
using WotBlitzStatisticsPro.Logic;
|
||||
|
||||
namespace WotBlitzStatisticsPro.GraphQl.Resolvers
|
||||
@@ -10,9 +10,11 @@ namespace WotBlitzStatisticsPro.GraphQl.Resolvers
|
||||
{
|
||||
protected override void Configure(IObjectTypeDescriptor<AccountInfoResponse> descriptor)
|
||||
{
|
||||
descriptor.Name("AccountInfoResponse");
|
||||
descriptor.Implements<StatisticsResponseType>();
|
||||
|
||||
descriptor.Field(t => t.ClanInfo)
|
||||
.Resolver(ctx => ctx.Service<IWargamingClans>().GelClanInfoByAccount(ctx.Parent<AccountInfoResponse>().AccountId, ctx.Operation.ParseOperation()));
|
||||
|
||||
.Resolver(ctx => ctx.Service<IWargamingClans>().GelClanInfoByAccount(ctx.Parent<AccountInfoResponse>().AccountId, ctx.Parent<AccountInfoResponse>().RegionAndLanguage));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Serilog;
|
||||
using WotBlitzStatisticsPro.Common;
|
||||
using WotBlitzStatisticsPro.Common.Model;
|
||||
using WotBlitzStatisticsPro.GraphQl.GitHubOauth;
|
||||
@@ -37,7 +38,10 @@ namespace WotBlitzStatisticsPro.GraphQl
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
var wgApiConfig = new WargamingApiSettings();
|
||||
//services.AddLogging(loggingBuilder =>
|
||||
// loggingBuilder.AddSerilog(dispose: true));
|
||||
|
||||
var wgApiConfig = new WargamingApiSettings();
|
||||
Configuration.GetSection("WargamingApi").Bind(wgApiConfig);
|
||||
|
||||
var mongoConfig = new MongoSettings();
|
||||
@@ -85,9 +89,12 @@ namespace WotBlitzStatisticsPro.GraphQl
|
||||
.AddType<WotBlitzStatisticsQuery>()
|
||||
.AddType<AccountInfoResolver>()
|
||||
.AddType<WotBlitzAchievementsQuery>()
|
||||
.AddType<TankInfoResponseType>()
|
||||
.AddType<WargamingAuthQuery>()
|
||||
.AddMutationType(d => d.Name("Mutation"))
|
||||
.AddType<WotBlitzStatisticsMutation>()
|
||||
.AddType<AuthenticationMutation>()
|
||||
.AddType<WargamingAuthMutation>()
|
||||
.AddType<AccountsSearchItemObjectType>()
|
||||
.AddEnumType<MarkOfMastery>()
|
||||
.AddEnumType<RealmType>()
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="5.0.4" />
|
||||
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.10.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.10.0" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -28,6 +29,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="DataLoaders\" />
|
||||
<Folder Include="Helpers\" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +1,25 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"Serilog": {
|
||||
"Using": [ "Serilog.Sinks.Console" ],
|
||||
"MinimumLevel": {
|
||||
"Default": "Debug",
|
||||
"Override": {
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information",
|
||||
"System": "Warning"
|
||||
}
|
||||
|
||||
},
|
||||
"WriteTo": [
|
||||
{ "Name": "Console" }
|
||||
],
|
||||
"Enrich": [ "FromLogContext" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"Serilog": {
|
||||
"Using": [ "Serilog.Sinks.Console" ],
|
||||
"MinimumLevel": {
|
||||
"Default": "Information",
|
||||
"Override": {
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information",
|
||||
"System": "Warning"
|
||||
}
|
||||
},
|
||||
"WriteTo": [
|
||||
{ "Name": "Console" }
|
||||
],
|
||||
"Enrich": [ "FromLogContext" ]
|
||||
}
|
||||
}
|
||||
@@ -14,9 +14,30 @@
|
||||
"Mongo": {
|
||||
"ConnectionString": "*",
|
||||
"DatabaseName": "*"
|
||||
},
|
||||
},
|
||||
"GitHubOAuth": {
|
||||
"ClientId": "YourClientId",
|
||||
"ClientSecret": "YourSecret"
|
||||
}
|
||||
}
|
||||
"ClientSecret": "YourSecret"
|
||||
},
|
||||
"Serilog": {
|
||||
"Using": [ "Serilog.Sinks.Console" ],
|
||||
"MinimumLevel": {
|
||||
"Default": "Information",
|
||||
"Override": {
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information",
|
||||
"System": "Warning"
|
||||
}
|
||||
},
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "Console",
|
||||
"Args": {
|
||||
"theme": "Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme::Code, Serilog.Sinks.Console",
|
||||
"outputTemplate": "{Timestamp:HH:mm:ss.fff} [{Level:u3}] {Message:lj} |{SourceContext}|{NewLine}{Exception}"
|
||||
}
|
||||
}
|
||||
],
|
||||
"Enrich": [ "FromLogContext" ]
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user