Fixed accidentally building the board from player2 perspective.
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
using Gameboard.Shogi.Api.ServiceModels.Messages;
|
||||
using Gameboard.ShogiUI.Sockets.Models;
|
||||
using Gameboard.ShogiUI.Sockets.Repositories.Utility;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -11,17 +14,17 @@ namespace Gameboard.ShogiUI.Sockets.Repositories
|
||||
public interface IGameboardRepository
|
||||
{
|
||||
Task DeleteGame(string gameName);
|
||||
Task<GetSessionResponse> GetGame(string gameName);
|
||||
Task<Session> GetGame(string gameName);
|
||||
Task<GetSessionsResponse> GetGames();
|
||||
Task<GetSessionsResponse> GetGames(string playerName);
|
||||
Task<GetMovesResponse> GetMoves(string gameName);
|
||||
Task<PostSessionResponse> PostSession(PostSession request);
|
||||
Task<PostJoinPrivateSessionResponse> PostJoinPrivateSession(PostJoinPrivateSession request);
|
||||
Task<PutJoinPublicSessionResponse> PutJoinPublicSession(PutJoinPublicSession request);
|
||||
Task<List<Move>> GetMoves(string gameName);
|
||||
Task<string> PostSession(PostSession request);
|
||||
Task<string> PostJoinPrivateSession(PostJoinPrivateSession request);
|
||||
Task<bool> PutJoinPublicSession(PutJoinPublicSession request);
|
||||
Task PostMove(string gameName, PostMove request);
|
||||
Task<PostJoinCodeResponse> PostJoinCode(string gameName, string userName);
|
||||
Task<GetPlayerResponse> GetPlayer(string userName);
|
||||
Task<HttpResponseMessage> PostPlayer(PostPlayer request);
|
||||
Task<string> PostJoinCode(string gameName, string userName);
|
||||
Task<Player> GetPlayer(string userName);
|
||||
Task<bool> PostPlayer(PostPlayer request);
|
||||
}
|
||||
|
||||
public class GameboardRepository : IGameboardRepository
|
||||
@@ -52,12 +55,16 @@ namespace Gameboard.ShogiUI.Sockets.Repositories
|
||||
return JsonConvert.DeserializeObject<GetSessionsResponse>(json);
|
||||
}
|
||||
|
||||
public async Task<GetSessionResponse> GetGame(string gameName)
|
||||
public async Task<Session> GetGame(string gameName)
|
||||
{
|
||||
var uri = $"Session/{gameName}";
|
||||
var response = await client.GetAsync(Uri.EscapeUriString(uri));
|
||||
var json = await response.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<GetSessionResponse>(json);
|
||||
if (string.IsNullOrWhiteSpace(json))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Session(JsonConvert.DeserializeObject<GetSessionResponse>(json).Session);
|
||||
}
|
||||
|
||||
public async Task DeleteGame(string gameName)
|
||||
@@ -66,36 +73,46 @@ namespace Gameboard.ShogiUI.Sockets.Repositories
|
||||
await client.DeleteAsync(Uri.EscapeUriString(uri));
|
||||
}
|
||||
|
||||
public async Task<PostSessionResponse> PostSession(PostSession request)
|
||||
public async Task<string> PostSession(PostSession request)
|
||||
{
|
||||
var content = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, MediaType);
|
||||
var response = await client.PostAsync(PostSessionRoute, content);
|
||||
var json = await response.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<PostSessionResponse>(json);
|
||||
return JsonConvert.DeserializeObject<PostSessionResponse>(json).SessionName;
|
||||
}
|
||||
|
||||
public async Task<PutJoinPublicSessionResponse> PutJoinPublicSession(PutJoinPublicSession request)
|
||||
public async Task<bool> PutJoinPublicSession(PutJoinPublicSession request)
|
||||
{
|
||||
var content = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, MediaType);
|
||||
var response = await client.PutAsync(JoinSessionRoute, content);
|
||||
var json = await response.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<PutJoinPublicSessionResponse>(json);
|
||||
return JsonConvert.DeserializeObject<PutJoinPublicSessionResponse>(json).JoinSucceeded;
|
||||
}
|
||||
|
||||
public async Task<PostJoinPrivateSessionResponse> PostJoinPrivateSession(PostJoinPrivateSession request)
|
||||
public async Task<string> PostJoinPrivateSession(PostJoinPrivateSession request)
|
||||
{
|
||||
var content = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, MediaType);
|
||||
var response = await client.PostAsync(JoinSessionRoute, content);
|
||||
var json = await response.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<PostJoinPrivateSessionResponse>(json);
|
||||
var deserialized = JsonConvert.DeserializeObject<PostJoinPrivateSessionResponse>(json);
|
||||
if (deserialized.JoinSucceeded)
|
||||
{
|
||||
return deserialized.SessionName;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<GetMovesResponse> GetMoves(string gameName)
|
||||
public async Task<List<Move>> GetMoves(string gameName)
|
||||
{
|
||||
var uri = $"Session/{gameName}/Moves";
|
||||
var response = await client.GetAsync(Uri.EscapeUriString(uri));
|
||||
var json = await response.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<GetMovesResponse>(json);
|
||||
var get = await client.GetAsync(Uri.EscapeUriString(uri));
|
||||
var json = await get.Content.ReadAsStringAsync();
|
||||
if (string.IsNullOrWhiteSpace(json))
|
||||
{
|
||||
return new List<Move>();
|
||||
}
|
||||
var response = JsonConvert.DeserializeObject<GetMovesResponse>(json);
|
||||
return response.Moves.Select(m => new Move(m)).ToList();
|
||||
}
|
||||
|
||||
public async Task PostMove(string gameName, PostMove request)
|
||||
@@ -105,27 +122,33 @@ namespace Gameboard.ShogiUI.Sockets.Repositories
|
||||
await client.PostAsync(Uri.EscapeUriString(uri), content);
|
||||
}
|
||||
|
||||
public async Task<PostJoinCodeResponse> PostJoinCode(string gameName, string userName)
|
||||
public async Task<string> PostJoinCode(string gameName, string userName)
|
||||
{
|
||||
var uri = $"JoinCode/{gameName}";
|
||||
var serialized = JsonConvert.SerializeObject(new PostJoinCode { PlayerName = userName });
|
||||
var content = new StringContent(serialized, Encoding.UTF8, MediaType);
|
||||
var json = await (await client.PostAsync(Uri.EscapeUriString(uri), content)).Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<PostJoinCodeResponse>(json);
|
||||
return JsonConvert.DeserializeObject<PostJoinCodeResponse>(json).JoinCode;
|
||||
}
|
||||
|
||||
public async Task<GetPlayerResponse> GetPlayer(string playerName)
|
||||
public async Task<Player> GetPlayer(string playerName)
|
||||
{
|
||||
var uri = $"Player/{playerName}";
|
||||
var response = await client.GetAsync(Uri.EscapeUriString(uri));
|
||||
var json = await response.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<GetPlayerResponse>(json);
|
||||
var get = await client.GetAsync(Uri.EscapeUriString(uri));
|
||||
var content = await get.Content.ReadAsStringAsync();
|
||||
if (!string.IsNullOrWhiteSpace(content))
|
||||
{
|
||||
var response = JsonConvert.DeserializeObject<GetPlayerResponse>(content);
|
||||
return new Player(response.Player.Name);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<HttpResponseMessage> PostPlayer(PostPlayer request)
|
||||
public async Task<bool> PostPlayer(PostPlayer request)
|
||||
{
|
||||
var content = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, MediaType);
|
||||
return await client.PostAsync(PlayerRoute, content);
|
||||
var response = await client.PostAsync(PlayerRoute, content);
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user