Merged in development (pull request #44)

Development
This commit is contained in:
2021-02-13 02:57:54 +00:00
4 changed files with 24 additions and 10 deletions

View File

@@ -18,9 +18,5 @@
<ProjectReference Include="..\Gameboard.ShogiUI.Sockets.ServiceModels\Gameboard.ShogiUI.Sockets.ServiceModels.csproj" /> <ProjectReference Include="..\Gameboard.ShogiUI.Sockets.ServiceModels\Gameboard.ShogiUI.Sockets.ServiceModels.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Models\" />
</ItemGroup>
</Project> </Project>

View File

@@ -35,7 +35,8 @@ namespace Gameboard.ShogiUI.Sockets.Managers.ClientActionHandlers
var joinGameResponse = await gameboardRepository.PutJoinPublicSession(request.GameName, new PutJoinPublicSession var joinGameResponse = await gameboardRepository.PutJoinPublicSession(request.GameName, new PutJoinPublicSession
{ {
PlayerName = userName PlayerName = userName,
SessionName = request.GameName
}); });
if (joinGameResponse.JoinSucceeded) if (joinGameResponse.JoinSucceeded)

View File

@@ -1,10 +1,10 @@
using Gameboard.Shogi.Api.ServiceModels.Messages; using Gameboard.Shogi.Api.ServiceModels.Messages;
using Gameboard.ShogiUI.Sockets.Repositories.Utility;
using Newtonsoft.Json; using Newtonsoft.Json;
using System; using System;
using System.Net.Http; using System.Net.Http;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Gameboard.ShogiUI.Sockets.Repositories.Utility;
namespace Gameboard.ShogiUI.Sockets.Repositories namespace Gameboard.ShogiUI.Sockets.Repositories
{ {
@@ -71,9 +71,9 @@ namespace Gameboard.ShogiUI.Sockets.Repositories
public async Task<PutJoinPublicSessionResponse> PutJoinPublicSession(string gameName, PutJoinPublicSession request) public async Task<PutJoinPublicSessionResponse> PutJoinPublicSession(string gameName, PutJoinPublicSession request)
{ {
var uri = $"Session/{gameName}/Join"; var uri = $"Session/Join";
var content = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json"); var content = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json");
var response = await client.PostAsync(Uri.EscapeUriString(uri), content); var response = await client.PutAsync(Uri.EscapeUriString(uri), content);
var json = await response.Content.ReadAsStringAsync(); var json = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<PutJoinPublicSessionResponse>(json); return JsonConvert.DeserializeObject<PutJoinPublicSessionResponse>(json);
} }
@@ -114,6 +114,7 @@ namespace Gameboard.ShogiUI.Sockets.Repositories
{ {
var uri = $"Player/{playerName}"; var uri = $"Player/{playerName}";
var response = await client.GetAsync(Uri.EscapeUriString(uri)); var response = await client.GetAsync(Uri.EscapeUriString(uri));
Console.WriteLine(response);
var json = await response.Content.ReadAsStringAsync(); var json = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<GetPlayerResponse>(json); return JsonConvert.DeserializeObject<GetPlayerResponse>(json);
} }

View File

@@ -13,6 +13,7 @@ namespace Gameboard.ShogiUI.Sockets.Repositories.Utility
Task<HttpResponseMessage> DeleteAsync(string requestUri); Task<HttpResponseMessage> DeleteAsync(string requestUri);
Task<HttpResponseMessage> GetAsync(string requestUri); Task<HttpResponseMessage> GetAsync(string requestUri);
Task<HttpResponseMessage> PostAsync(string requestUri, HttpContent content); Task<HttpResponseMessage> PostAsync(string requestUri, HttpContent content);
Task<HttpResponseMessage> PutAsync(string requestUri, HttpContent content);
} }
public class AuthenticatedHttpClient : HttpClient, IAuthenticatedHttpClient public class AuthenticatedHttpClient : HttpClient, IAuthenticatedHttpClient
@@ -31,7 +32,6 @@ namespace Gameboard.ShogiUI.Sockets.Repositories.Utility
clientSecret = configuration["AppSettings:ClientSecret"]; clientSecret = configuration["AppSettings:ClientSecret"];
BaseAddress = new Uri(configuration["AppSettings:GameboardShogiApi"]); BaseAddress = new Uri(configuration["AppSettings:GameboardShogiApi"]);
} }
private async Task RefreshBearerToken() private async Task RefreshBearerToken()
{ {
var disco = await this.GetDiscoveryDocumentAsync(identityServerUrl); var disco = await this.GetDiscoveryDocumentAsync(identityServerUrl);
@@ -56,7 +56,23 @@ namespace Gameboard.ShogiUI.Sockets.Repositories.Utility
logger.LogInformation("Refreshing Bearer Token to {BaseAddress}", BaseAddress); logger.LogInformation("Refreshing Bearer Token to {BaseAddress}", BaseAddress);
this.SetBearerToken(tokenResponse.AccessToken); this.SetBearerToken(tokenResponse.AccessToken);
} }
public async new Task<HttpResponseMessage> PutAsync(string requestUri, HttpContent content)
{
var response = await base.PutAsync(requestUri, content);
if (response.StatusCode == HttpStatusCode.Unauthorized)
{
await RefreshBearerToken();
response = await base.PostAsync(requestUri, content);
}
logger.LogInformation(
"Repository PUT to {BaseUrl}{RequestUrl} \n\tRespCode: {RespCode} \n\tRequest: {Request}\n\tResponse: {Response}\n",
BaseAddress,
requestUri,
response.StatusCode,
await content.ReadAsStringAsync(),
await response.Content.ReadAsStringAsync());
return response;
}
public async new Task<HttpResponseMessage> GetAsync(string requestUri) public async new Task<HttpResponseMessage> GetAsync(string requestUri)
{ {
var response = await base.GetAsync(requestUri); var response = await base.GetAsync(requestUri);