Move from the hand.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
@@ -73,6 +73,15 @@ public class SessionRepository : ISessionRepository
|
||||
|
||||
public async Task CreateMove(string sessionName, MovePieceCommand command)
|
||||
{
|
||||
var yep = new
|
||||
{
|
||||
command.To,
|
||||
command.From,
|
||||
command.IsPromotion,
|
||||
command.PieceFromHand,
|
||||
SessionName = sessionName
|
||||
};
|
||||
|
||||
using var connection = new SqlConnection(connectionString);
|
||||
await connection.ExecuteAsync(
|
||||
"session.CreateMove",
|
||||
@@ -81,7 +90,7 @@ public class SessionRepository : ISessionRepository
|
||||
command.To,
|
||||
command.From,
|
||||
command.IsPromotion,
|
||||
command.PieceFromHand,
|
||||
PieceFromHand = command.PieceFromHand.ToString(),
|
||||
SessionName = sessionName
|
||||
},
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
Reference in New Issue
Block a user