yep
This commit is contained in:
@@ -39,7 +39,7 @@ public class SessionsController : ControllerBase
|
||||
public async Task<IActionResult> CreateSession([FromBody] CreateSessionCommand request)
|
||||
{
|
||||
var userId = User.GetShogiUserId();
|
||||
var session = new Domain.Aggregates.Session(request.Name, userId);
|
||||
var session = new Domain.Session(request.Name, userId);
|
||||
try
|
||||
{
|
||||
await sessionRepository.CreateSession(session);
|
||||
@@ -126,7 +126,7 @@ public class SessionsController : ControllerBase
|
||||
}
|
||||
else
|
||||
{
|
||||
session.Board.Move(command.From!, command.To, command.IsPromotion);
|
||||
session.Board.Move(command.From!, command.To, command.IsPromotion!.Value);
|
||||
}
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
|
||||
@@ -50,6 +50,7 @@ public static class ContractsExtensions
|
||||
public static Dictionary<string, Piece?> ToContract(this ReadOnlyDictionary<string, Domain.ValueObjects.Piece?> boardState) =>
|
||||
boardState.ToDictionary(kvp => kvp.Key, kvp => kvp.Value?.ToContract());
|
||||
|
||||
public static Domain.WhichPiece? ToDomain(this WhichPiece? piece) => piece.HasValue ? piece.Value.ToDomain() : null;
|
||||
public static Domain.WhichPiece ToDomain(this WhichPiece piece)
|
||||
{
|
||||
return piece switch
|
||||
|
||||
@@ -5,6 +5,6 @@ namespace Shogi.Api.Repositories.Dto;
|
||||
/// <summary>
|
||||
/// Useful with Dapper to read from database.
|
||||
/// </summary>
|
||||
public readonly record struct MoveDto(string From, string To, bool IsPromotion, WhichPiece? PieceFromHand)
|
||||
public readonly record struct MoveDto(string? From, string To, bool? IsPromotion, WhichPiece? PieceFromHand)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Dapper;
|
||||
using Shogi.Api.Extensions;
|
||||
using Shogi.Api.Repositories.Dto;
|
||||
using Shogi.Domain.Aggregates;
|
||||
using Shogi.Domain;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
@@ -65,6 +66,15 @@ public class SessionRepository : ISessionRepository
|
||||
}
|
||||
return session;
|
||||
}
|
||||
|
||||
public async Task CreateMove(string sessionName, Contracts.Api.MovePieceCommand command)
|
||||
{
|
||||
using var connection = new SqlConnection(connectionString);
|
||||
await connection.ExecuteAsync(
|
||||
"session.CreateMove",
|
||||
new { },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
}
|
||||
}
|
||||
|
||||
public interface ISessionRepository
|
||||
|
||||
Reference in New Issue
Block a user