Move from the hand.

This commit is contained in:
2023-02-01 22:49:28 -06:00
parent e2eff4f8b5
commit 3bf9aa3ee3
29 changed files with 248 additions and 133 deletions

View File

@@ -1,6 +1,7 @@
using Dapper;
using Shogi.Contracts.Api;
using Shogi.Contracts.Types;
using System.Data;
using System.Data.SqlClient;
namespace Shogi.Api.Repositories;
@@ -32,9 +33,33 @@ public class QueryRepository : IQueryRespository
AllOtherSessions = otherSessions.ToList()
};
}
/// <summary>
/// </summary>
/// <returns>A <see cref="ValueTuple"/> with Item1 as player 1 and Item2 as player 2.</returns>
public async Task<(User Player1, User? Player2)?> GetUsersForSession(string sessionName)
{
using var connection = new SqlConnection(connectionString);
var results = await connection.QueryAsync<(string Player1Name, string Player1DisplayName, string Player2Name, string Player2DisplayName)>(
"session.ReadUsersBySession",
new { SessionName = sessionName },
commandType: CommandType.StoredProcedure);
if (results.Any())
{
var (Player1Name, Player1DisplayName, Player2Name, Player2DisplayName) = results.First();
var p1 = new User(Player1Name, Player1DisplayName);
var p2 = Player2Name != null
? new User(Player2Name, Player2DisplayName)
: null;
return (p1, p2);
}
return null;
}
}
public interface IQueryRespository
{
Task<(User Player1, User? Player2)?> GetUsersForSession(string sessionName);
Task<ReadSessionsPlayerCountResponse> ReadSessionPlayerCount(string playerName);
}