Upgrade to .net 5

Address breaking changes from Shogi.API nuget
This commit is contained in:
2021-01-23 18:11:19 -06:00
parent 1bbab8fe8f
commit 2c8e692d38
15 changed files with 71 additions and 99 deletions

View File

@@ -11,13 +11,13 @@ namespace Websockets.Repositories
public interface IGameboardRepository
{
Task DeleteGame(string gameName);
Task<GetGameResponse> GetGame(string gameName);
Task<GetGamesResponse> GetGames();
Task<GetGamesResponse> GetGames(string playerName);
Task<GetSessionResponse> GetGame(string gameName);
Task<GetSessionsResponse> GetGames();
Task<GetSessionsResponse> GetGames(string playerName);
Task<GetMovesResponse> GetMoves(string gameName);
Task<PostGameResponse> PostGame(PostGame request);
Task<PostJoinByCodeResponse> PostJoinByCode(PostJoinByCode request);
Task<PostJoinGameResponse> PostJoinGame(string gameName, PostJoinGame request);
Task<PostSessionResponse> PostSession(PostSession request);
Task<PostJoinPrivateSessionResponse> PostJoinPrivateSession(PostJoinPrivateSession request);
Task<PutJoinPublicSessionResponse> PutJoinPublicSession(string gameName, PutJoinPublicSession request);
Task PostMove(string gameName, PostMove request);
Task<PostJoinCodeResponse> PostJoinCode(string gameName, string userName);
Task<GetPlayerResponse> GetPlayer(string userName);
@@ -32,63 +32,63 @@ namespace Websockets.Repositories
this.client = client;
}
public async Task<GetGamesResponse> GetGames()
public async Task<GetSessionsResponse> GetGames()
{
var response = await client.GetAsync("Games");
var response = await client.GetAsync("Sessions");
var json = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<GetGamesResponse>(json);
return JsonConvert.DeserializeObject<GetSessionsResponse>(json);
}
public async Task<GetGamesResponse> GetGames(string playerName)
public async Task<GetSessionsResponse> GetGames(string playerName)
{
var uri = $"Games/{playerName}";
var uri = $"Sessions/{playerName}";
var response = await client.GetAsync(Uri.EscapeUriString(uri));
var json = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<GetGamesResponse>(json);
return JsonConvert.DeserializeObject<GetSessionsResponse>(json);
}
public async Task<GetGameResponse> GetGame(string gameName)
public async Task<GetSessionResponse> GetGame(string gameName)
{
var uri = $"Game/{gameName}";
var uri = $"Session/{gameName}";
var response = await client.GetAsync(Uri.EscapeUriString(uri));
var json = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<GetGameResponse>(json);
return JsonConvert.DeserializeObject<GetSessionResponse>(json);
}
public async Task DeleteGame(string gameName)
{
var uri = $"Game/{gameName}";
var uri = $"Session/{gameName}";
await client.DeleteAsync(Uri.EscapeUriString(uri));
}
public async Task<PostGameResponse> PostGame(PostGame request)
public async Task<PostSessionResponse> PostSession(PostSession request)
{
var content = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json");
var response = await client.PostAsync("Game", content);
var response = await client.PostAsync("Session", content);
var json = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<PostGameResponse>(json);
return JsonConvert.DeserializeObject<PostSessionResponse>(json);
}
public async Task<PostJoinGameResponse> PostJoinGame(string gameName, PostJoinGame request)
public async Task<PutJoinPublicSessionResponse> PutJoinPublicSession(string gameName, PutJoinPublicSession request)
{
var uri = $"Game/{gameName}/Join";
var uri = $"Session/{gameName}/Join";
var content = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json");
var response = await client.PostAsync(Uri.EscapeUriString(uri), content);
var json = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<PostJoinGameResponse>(json);
return JsonConvert.DeserializeObject<PutJoinPublicSessionResponse>(json);
}
public async Task<PostJoinByCodeResponse> PostJoinByCode(PostJoinByCode request)
public async Task<PostJoinPrivateSessionResponse> PostJoinPrivateSession(PostJoinPrivateSession request)
{
var content = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json");
var response = await client.PostAsync("Game/Join", content);
var response = await client.PostAsync("Session/Join", content);
var json = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<PostJoinByCodeResponse>(json);
return JsonConvert.DeserializeObject<PostJoinPrivateSessionResponse>(json);
}
public async Task<GetMovesResponse> GetMoves(string gameName)
{
var uri = $"Game/{gameName}/Moves";
var uri = $"Session/{gameName}/Moves";
var response = await client.GetAsync(Uri.EscapeUriString(uri));
var json = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<GetMovesResponse>(json);
@@ -96,7 +96,7 @@ namespace Websockets.Repositories
public async Task PostMove(string gameName, PostMove request)
{
var uri = $"Game/{gameName}/Move";
var uri = $"Session/{gameName}/Move";
var content = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json");
await client.PostAsync(Uri.EscapeUriString(uri), content);
}

View File

@@ -1,32 +0,0 @@
using Gameboard.Shogi.Api.ServiceModels.Messages;
using Newtonsoft.Json;
using System;
using System.Threading.Tasks;
using Websockets.Repositories.Utility;
namespace Websockets.Repositories
{
[Obsolete("Use GameboardRepository. Functions from PlayerRepository will be moved.")]
public class PlayerRepository
{
private readonly IAuthenticatedHttpClient client;
public PlayerRepository(IAuthenticatedHttpClient client)
{
this.client = client;
}
public async Task<GetPlayerResponse> GetPlayer(string playerName)
{
var response = await client.GetAsync($"/Player/{playerName}");
var json = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<GetPlayerResponse>(json);
}
public async Task DeletePlayer(string playerName)
{
var response = await client.DeleteAsync($"/Player/{playerName}");
await response.Content.ReadAsStringAsync();
}
}
}

View File

@@ -81,9 +81,10 @@ namespace Websockets.Repositories.Utility
response = await base.PostAsync(requestUri, content);
}
logger.LogInformation(
"Repository POST to {BaseUrl}{RequestUrl} \nRequest: {Request}\nResponse: {Response}\n",
"Repository POST 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;