Working on "Join Game" feature.
This commit is contained in:
@@ -12,5 +12,6 @@ public interface IShogiApi
|
||||
Task<CreateTokenResponse?> GetToken(WhichAccountPlatform whichAccountPlatform);
|
||||
Task GuestLogout();
|
||||
Task Move(string sessionName, MovePieceCommand move);
|
||||
Task<HttpStatusCode> PostSession(string name, bool isPrivate);
|
||||
Task<HttpStatusCode> PatchJoinGame(string name);
|
||||
Task<HttpStatusCode> PostSession(string name, bool isPrivate);
|
||||
}
|
||||
@@ -28,7 +28,7 @@ namespace Shogi.UI.Pages.Home.Api
|
||||
{
|
||||
WhichAccountPlatform.Guest => clientFactory.CreateClient(GuestClientName),
|
||||
WhichAccountPlatform.Microsoft => clientFactory.CreateClient(MsalClientName),
|
||||
_ => clientFactory.CreateClient(GuestClientName)
|
||||
_ => throw new InvalidOperationException("AccountState.User must not be null during API call.")
|
||||
};
|
||||
|
||||
public async Task GuestLogout()
|
||||
@@ -49,7 +49,7 @@ namespace Shogi.UI.Pages.Home.Api
|
||||
|
||||
public async Task<ReadSessionsPlayerCountResponse?> GetSessionsPlayerCount()
|
||||
{
|
||||
var response = await HttpClient.GetAsync(new Uri("Sessions/PlayerCount", UriKind.Relative));
|
||||
var response = await HttpClient.GetAsync(RelativeUri("Sessions/PlayerCount"));
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
return await response.Content.ReadFromJsonAsync<ReadSessionsPlayerCountResponse>(serializerOptions);
|
||||
@@ -57,12 +57,15 @@ namespace Shogi.UI.Pages.Home.Api
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Logs the user into the API and returns a token which can be used to request a socket connection.
|
||||
/// </summary>
|
||||
public async Task<CreateTokenResponse?> GetToken(WhichAccountPlatform whichAccountPlatform)
|
||||
{
|
||||
var httpClient = whichAccountPlatform == WhichAccountPlatform.Microsoft
|
||||
? clientFactory.CreateClient(MsalClientName)
|
||||
: clientFactory.CreateClient(GuestClientName);
|
||||
var response = await httpClient.GetFromJsonAsync<CreateTokenResponse>(new Uri("User/Token", UriKind.Relative), serializerOptions);
|
||||
var response = await httpClient.GetFromJsonAsync<CreateTokenResponse>(RelativeUri("User/Token"), serializerOptions);
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -73,11 +76,19 @@ namespace Shogi.UI.Pages.Home.Api
|
||||
|
||||
public async Task<HttpStatusCode> PostSession(string name, bool isPrivate)
|
||||
{
|
||||
var response = await HttpClient.PostAsJsonAsync(new Uri("Sessions", UriKind.Relative), new CreateSessionCommand
|
||||
var response = await HttpClient.PostAsJsonAsync(RelativeUri("Sessions"), new CreateSessionCommand
|
||||
{
|
||||
Name = name,
|
||||
});
|
||||
return response.StatusCode;
|
||||
}
|
||||
|
||||
public async Task<HttpStatusCode> PatchJoinGame(string name)
|
||||
{
|
||||
var response = await HttpClient.PatchAsync(RelativeUri($"Sessions/{name}/Join"), null);
|
||||
return response.StatusCode;
|
||||
}
|
||||
|
||||
private static Uri RelativeUri(string path) => new Uri(path, UriKind.Relative);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user