before deleting Rules

This commit is contained in:
2021-05-08 10:26:04 -05:00
parent 05a9c71499
commit f8f779e84c
80 changed files with 1109 additions and 832 deletions

View File

@@ -1,16 +1,19 @@
using Gameboard.ShogiUI.Sockets.Models;
using Gameboard.ShogiUI.Sockets.Repositories;
using Gameboard.ShogiUI.Sockets.Repositories;
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Messages;
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket.Types;
using Newtonsoft.Json;
using System.Linq;
using System.Threading.Tasks;
namespace Gameboard.ShogiUI.Sockets.Managers.ClientActionHandlers
{
public interface IListGamesHandler
{
Task Handle(ListGamesRequest request, string userName);
}
// TODO: This doesn't need to be a socket action.
// It can be an HTTP route.
public class ListGamesHandler : IActionHandler
public class ListGamesHandler : IListGamesHandler
{
private readonly ISocketCommunicationManager communicationManager;
private readonly IGameboardRepository repository;
@@ -23,16 +26,10 @@ namespace Gameboard.ShogiUI.Sockets.Managers.ClientActionHandlers
this.repository = repository;
}
public async Task Handle(string json, string userName)
public async Task Handle(ListGamesRequest _, string userName)
{
var request = JsonConvert.DeserializeObject<ListGamesRequest>(json);
var getGamesResponse = string.IsNullOrWhiteSpace(userName)
? await repository.GetGames()
: await repository.GetGames(userName);
var games = getGamesResponse.Sessions
.OrderBy(s => s.Player1 == userName || s.Player2 == userName)
.Select(s => new Session(s).ToServiceModel()); // yuck
var sessions = await repository.ReadSessions();
var games = sessions.Select(s => s.ToServiceModel()); // yuck
var response = new ListGamesResponse(ClientAction.ListGames)
{