before deleting Rules
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user