41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
using Gameboard.ShogiUI.Sockets.Repositories;
|
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Socket;
|
|
using Gameboard.ShogiUI.Sockets.ServiceModels.Types;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Gameboard.ShogiUI.Sockets.Managers.ClientActionHandlers
|
|
{
|
|
public interface IListGamesHandler
|
|
{
|
|
Task Handle(ListGamesRequest request, string userName);
|
|
}
|
|
|
|
public class ListGamesHandler : IListGamesHandler
|
|
{
|
|
private readonly ISocketConnectionManager communicationManager;
|
|
private readonly IGameboardRepository repository;
|
|
|
|
public ListGamesHandler(
|
|
ISocketConnectionManager communicationManager,
|
|
IGameboardRepository repository)
|
|
{
|
|
this.communicationManager = communicationManager;
|
|
this.repository = repository;
|
|
}
|
|
|
|
public async Task Handle(ListGamesRequest _, string userName)
|
|
{
|
|
var sessions = await repository.ReadSessionMetadatas();
|
|
var games = sessions.Select(s => new Game(s.Name, s.Player1, s.Player2)).ToList();
|
|
|
|
var response = new ListGamesResponse()
|
|
{
|
|
Games = games
|
|
};
|
|
|
|
await communicationManager.BroadcastToPlayers(response, userName);
|
|
}
|
|
}
|
|
}
|