This commit is contained in:
2023-01-28 13:21:47 -06:00
parent 11b387b928
commit 8a25c0ed35
26 changed files with 443 additions and 359 deletions

View File

@@ -12,6 +12,6 @@ public interface IShogiApi
Task<CreateTokenResponse?> GetToken(WhichAccountPlatform whichAccountPlatform);
Task GuestLogout();
Task Move(string sessionName, MovePieceCommand move);
Task<HttpStatusCode> PatchJoinGame(string name);
Task<HttpResponseMessage> PatchJoinGame(string name);
Task<HttpStatusCode> PostSession(string name, bool isPrivate);
}

View File

@@ -65,8 +65,16 @@ namespace Shogi.UI.Pages.Home.Api
var httpClient = whichAccountPlatform == WhichAccountPlatform.Microsoft
? clientFactory.CreateClient(MsalClientName)
: clientFactory.CreateClient(GuestClientName);
var response = await httpClient.GetFromJsonAsync<CreateTokenResponse>(RelativeUri("User/Token"), serializerOptions);
return response;
var response = await httpClient.GetAsync(RelativeUri("User/Token"));
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
if (!string.IsNullOrEmpty(content))
{
return await response.Content.ReadFromJsonAsync<CreateTokenResponse>(serializerOptions);
}
}
return null;
}
public async Task Move(string sessionName, MovePieceCommand command)
@@ -83,10 +91,9 @@ namespace Shogi.UI.Pages.Home.Api
return response.StatusCode;
}
public async Task<HttpStatusCode> PatchJoinGame(string name)
public Task<HttpResponseMessage> PatchJoinGame(string name)
{
var response = await HttpClient.PatchAsync(RelativeUri($"Sessions/{name}/Join"), null);
return response.StatusCode;
return HttpClient.PatchAsync(RelativeUri($"Sessions/{name}/Join"), null);
}
private static Uri RelativeUri(string path) => new Uri(path, UriKind.Relative);