Skip to content

Commit

Permalink
some refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Itoktsnhc committed Sep 6, 2023
1 parent 746734d commit 3160677
Show file tree
Hide file tree
Showing 42 changed files with 374 additions and 858 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -355,3 +355,4 @@ Stat.Itok.Front/dist
/Stat.Itok.Tests/configs/doc_id_list.txt
Stat.Itok.Tests/configs/rerun_list.txt
Stat.Itok.Tests/configs/user_auth_cfg.json
Stat.Itok.Worker/appsettings.dev.json
26 changes: 13 additions & 13 deletions Stat.Itok.Core/Handlers/NintendoHandlers.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using MediatR;
using Mediator;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
using Stat.Itok.Core.ApiClients;
Expand Down Expand Up @@ -30,7 +30,7 @@ public NintendoPublicHandlers(
}


public async Task<NinTokenCopyInfo> Handle(ReqGetTokenCopyInfo request, CancellationToken cancellationToken)
public async ValueTask<NinTokenCopyInfo> Handle(ReqGetTokenCopyInfo request, CancellationToken cancellationToken)
{
var authCode = StatInkHelper.BuildRandomSizedBased64Str(32);
var authCodeVerifier = StatInkHelper.BuildRandomSizedBased64Str(64);
Expand All @@ -42,7 +42,7 @@ public async Task<NinTokenCopyInfo> Handle(ReqGetTokenCopyInfo request, Cancella
};
}

public async Task<NinAuthContext> Handle(ReqGenAuthContext request, CancellationToken cancellationToken)
public async ValueTask<NinAuthContext> Handle(ReqGenAuthContext request, CancellationToken cancellationToken)
{
var sessionToken = await _mediator.Send(new ReqGetSessionToken()
{
Expand All @@ -59,7 +59,7 @@ public async Task<NinAuthContext> Handle(ReqGenAuthContext request, Cancellation
}, cancellationToken);
}

public async Task<NinAuthContext> Handle(ReqReGenAuthContext request, CancellationToken cancellationToken)
public async ValueTask<NinAuthContext> Handle(ReqReGenAuthContext request, CancellationToken cancellationToken)
{
var accessTokenInfo = await _mediator.Send(new ReqGetAccessToken()
{
Expand Down Expand Up @@ -101,15 +101,15 @@ public async Task<NinAuthContext> Handle(ReqReGenAuthContext request, Cancellati
return ctx;
}

public async Task<string> Handle(ReqDoGraphQL request, CancellationToken cancellationToken)
public async ValueTask<string> Handle(ReqDoGraphQL request, CancellationToken cancellationToken)
{
var strResp = await RunWithDefaultPolicy(_api.SendGraphQLRequestAsync(request.AuthContext.GameToken,
request.AuthContext.BulletToken, request.AuthContext.UserInfo, request.QueryHash, request.VarName,
request.VarValue));
return strResp;
}

public async Task<RespPreCheck> Handle(ReqPreCheck request, CancellationToken cancellationToken)
public async ValueTask<RespPreCheck> Handle(ReqPreCheck request, CancellationToken cancellationToken)
{
var checkResp = PreCheckResult.Ok;
NinAuthContext newAuthContext = request.AuthContext;
Expand Down Expand Up @@ -146,7 +146,7 @@ public async Task<RespPreCheck> Handle(ReqPreCheck request, CancellationToken ca
};
}

public async Task<NinMiscConfig> Handle(ReqGetNinMiscConfig request, CancellationToken cancellationToken)
public async ValueTask<NinMiscConfig> Handle(ReqGetNinMiscConfig request, CancellationToken cancellationToken)
{
return await _api.GetNinMiscConfigAsync();
}
Expand All @@ -167,7 +167,7 @@ public NintendoPrivateHandlers(INintendoApi api)
_api = api;
}

public async Task<string> Handle(ReqGetSessionToken request, CancellationToken cancellationToken)
public async ValueTask<string> Handle(ReqGetSessionToken request, CancellationToken cancellationToken)
{
var strResp = await RunWithDefaultPolicy(_api.GetSessionTokenAsync(request.TokenCopyInfo.RedirectUrl,
request.TokenCopyInfo.AuthCodeVerifier));
Expand All @@ -176,7 +176,7 @@ public async Task<string> Handle(ReqGetSessionToken request, CancellationToken c
return jTokenResp["session_token"]!.Value<string>();
}

public async Task<NinAccessTokenInfo> Handle(ReqGetAccessToken request, CancellationToken cancellationToken)
public async ValueTask<NinAccessTokenInfo> Handle(ReqGetAccessToken request, CancellationToken cancellationToken)
{
var strResp = await RunWithDefaultPolicy(_api.GetAccessTokenInfoAsync(request.SessionToken));
var jTokenResp = strResp.ThrowIfJsonPropNotFound("access_token", "id_token");
Expand All @@ -187,7 +187,7 @@ public async Task<NinAccessTokenInfo> Handle(ReqGetAccessToken request, Cancella
};
}

public async Task<NinUserInfo> Handle(ReqGetUserInfo request, CancellationToken cancellationToken)
public async ValueTask<NinUserInfo> Handle(ReqGetUserInfo request, CancellationToken cancellationToken)
{
var strResp = await RunWithDefaultPolicy(_api.GetUserInfoAsync(request.AccessTokenInfo.AccessToken));
var jTokenResp = strResp.ThrowIfJsonPropNotFound("id", "country", "language", "nickname", "birthday");
Expand All @@ -201,7 +201,7 @@ public async Task<NinUserInfo> Handle(ReqGetUserInfo request, CancellationToken
};
}

public async Task<RespPerGameToken> Handle(ReqGetPreGameToken request, CancellationToken cancellationToken)
public async ValueTask<RespPerGameToken> Handle(ReqGetPreGameToken request, CancellationToken cancellationToken)
{
var strResp =
await RunWithDefaultPolicy(_api.GetPreGameTokenAsync(request.AccessTokenInfo.AccessToken, request.User));
Expand All @@ -216,7 +216,7 @@ public async Task<RespPerGameToken> Handle(ReqGetPreGameToken request, Cancellat
};
}

public async Task<string> Handle(ReqGetGameToken request, CancellationToken cancellationToken)
public async ValueTask<string> Handle(ReqGetGameToken request, CancellationToken cancellationToken)
{
var strResp =
await RunWithDefaultPolicy(_api.GetGameTokenAsync(request.PreGameToken, request.User, request.CoralUserId));
Expand All @@ -226,7 +226,7 @@ public async Task<string> Handle(ReqGetGameToken request, CancellationToken canc
return jTokenResp["result"]!["accessToken"]!.Value<string>();
}

public async Task<string> Handle(ReqGetBulletGameToken request, CancellationToken cancellationToken)
public async ValueTask<string> Handle(ReqGetBulletGameToken request, CancellationToken cancellationToken)
{
var strResp =
await RunWithDefaultPolicy(_api.GetBulletTokenAsync(request.GameToken, request.User));
Expand Down
2 changes: 1 addition & 1 deletion Stat.Itok.Core/Handlers/ReqAndResp.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using MediatR;
using Mediator;

namespace Stat.Itok.Core.Handlers;

Expand Down
12 changes: 6 additions & 6 deletions Stat.Itok.Core/Handlers/StatInkHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using MediatR;
using Mediator;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
using Stat.Itok.Core.ApiClients;
Expand All @@ -23,7 +23,7 @@ public StatInkHandler(IStatInkApi api, ILogger<StatInkHandler> logger)
_logger = logger;
}

public async Task<StatInkPostBodySuccess> Handle(ReqPostBattle request, CancellationToken cancellationToken)
public async ValueTask<StatInkPostBodySuccess> Handle(ReqPostBattle request, CancellationToken cancellationToken)
{
var strResp = await RunWithDefaultPolicy(_api.PostBattleAsync(request.ApiKey, request.Body));
var jTokenResp = strResp.ThrowIfJsonPropNotFound("id", "url");
Expand All @@ -34,7 +34,7 @@ public async Task<StatInkPostBodySuccess> Handle(ReqPostBattle request, Cancella
};
}

public async Task<Dictionary<string, string>> Handle(ReqGetGearsInfo request, CancellationToken cancellationToken)
public async ValueTask<Dictionary<string, string>> Handle(ReqGetGearsInfo request, CancellationToken cancellationToken)
{
var strResp = await RunWithDefaultPolicy(_api.GetGearKeyDictAsync());
return JArray.Parse(strResp).SelectMany(x =>
Expand All @@ -52,7 +52,7 @@ public async Task<Dictionary<string, string>> Handle(ReqGetGearsInfo request, Ca
}).GroupBy(x => x.Item1).ToDictionary(x => x.Key, y => y.First().Item2);
}

public async Task<Dictionary<string, string>> Handle(ReqGetSalmonWeaponsInfo request,
public async ValueTask<Dictionary<string, string>> Handle(ReqGetSalmonWeaponsInfo request,
CancellationToken cancellationToken)
{
var strResp = await RunWithDefaultPolicy(_api.GetSalmonWeaponKeyDictAsync());
Expand All @@ -71,7 +71,7 @@ public async Task<Dictionary<string, string>> Handle(ReqGetSalmonWeaponsInfo req
}).GroupBy(x => x.Item1).ToDictionary(x => x.Key, y => y.First().Item2);
}

public async Task<StatInkPostBodySuccess> Handle(ReqPostSalmon request, CancellationToken cancellationToken)
public async ValueTask<StatInkPostBodySuccess> Handle(ReqPostSalmon request, CancellationToken cancellationToken)
{
var strResp = await RunWithDefaultPolicy(_api.PostSalmonAsync(request.ApiKey, request.Body));
var jTokenResp = strResp.ThrowIfJsonPropNotFound("id", "url");
Expand All @@ -82,7 +82,7 @@ public async Task<StatInkPostBodySuccess> Handle(ReqPostSalmon request, Cancella
};
}

public async Task<ApiResp<string>> Handle(ReqTestStatApiKey request, CancellationToken cancellationToken)
public async ValueTask<ApiResp<string>> Handle(ReqTestStatApiKey request, CancellationToken cancellationToken)
{
try
{
Expand Down
41 changes: 0 additions & 41 deletions Stat.Itok.Core/Handlers/_Pipelines.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Stat.Itok.Core/Stat.Itok.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageReference Include="Fizzler.Systems.HtmlAgilityPack" Version="1.2.1" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.46" />
<PackageReference Include="Mapster" Version="7.3.0" />
<PackageReference Include="MediatR" Version="11.0.0" />
<PackageReference Include="Mediator.Abstractions" Version="2.1.5" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.31.2" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
Expand Down
15 changes: 8 additions & 7 deletions Stat.Itok.Core/StorageAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public async Task<ItemResponse<CosmosEntity<TEntity>>> UpsertEntityInStoreAsync<
{
var cName = _options.Value.CosmosContainerName;
var container = _client.GetContainer(_options.Value.CosmosDbName, cName);
return await container.UpsertItemAsync(CosmosEntity.CreateFrom(CosmosEntity.BuildCosmosRealId<TEntity>(entityId, _options.Value.CosmosDbPkPrefix),
return await container.UpsertItemAsync(CosmosEntity.CreateFrom(
CosmosEntity.BuildCosmosRealId<TEntity>(entityId, _options.Value.CosmosDbPkPrefix),
entity, _options.Value.CosmosDbPkPrefix));
}

Expand All @@ -85,21 +86,21 @@ public async Task<TEntity> GetEntityIfExistAsync<TEntity>(string id)
var container = _client.GetContainer(_options.Value.CosmosDbName, _options.Value.CosmosContainerName);
try
{
var resp = await container.ReadItemAsync<CosmosEntity<TEntity>>(CosmosEntity.BuildCosmosRealId<TEntity>(id, _options.Value.CosmosDbPkPrefix),
new PartitionKey(CosmosEntity.GetPartitionKey<TEntity>(_options.Value.CosmosDbPkPrefix)));
var resp = await container.ReadItemAsync<CosmosEntity<TEntity>>(
CosmosEntity.BuildCosmosRealId<TEntity>(id, _options.Value.CosmosDbPkPrefix),
new PartitionKey(CosmosEntity.GetPartitionKey<TEntity>(_options.Value.CosmosDbPkPrefix)));
return resp.Resource.Data;
}
catch (Exception)
{
return default;
}

}
}

public interface IStorageAccessor
{
Task<QueueClient> GeJobRunTaskQueueClientAsync();
Task<QueueClient> GetJobRunTaskQueueClientAsync();
Task<BlobContainerClient> GetBlobContainerClientAsync<T>();
}

Expand Down Expand Up @@ -147,9 +148,9 @@ public async Task<TableClient> GetTableClientAsync<T>()
return tableClient;
}

public async Task<QueueClient> GeJobRunTaskQueueClientAsync()
public async Task<QueueClient> GetJobRunTaskQueueClientAsync()
{
var serviceClient = new QueueServiceClient(Environment.GetEnvironmentVariable("WorkerQueueConnStr"));
var serviceClient = new QueueServiceClient(_options.Value.StorageAccountConnStr);
var queueClient = serviceClient.GetQueueClient(StatItokConstants.JobRunTaskQueueName);
await queueClient.CreateIfNotExistsAsync();
return queueClient;
Expand Down
1 change: 0 additions & 1 deletion Stat.Itok.Func.Worker/.dockerignore

This file was deleted.

Loading

0 comments on commit 3160677

Please sign in to comment.