yep
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
namespace Shogi.Api.Repositories.Dto
|
||||
{
|
||||
/// <summary>
|
||||
/// Useful with Dapper to read from database.
|
||||
/// </summary>
|
||||
public class SessionDto
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Dapper;
|
||||
using Shogi.Api.Repositories.Dto;
|
||||
using Shogi.Contracts.Types;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
@@ -24,7 +25,7 @@ public class QueryRepository : IQueryRespository
|
||||
public async Task<SessionMetadata?> ReadSession(string name)
|
||||
{
|
||||
using var connection = new SqlConnection(connectionString);
|
||||
var results = await connection.QueryAsync<SessionMetadata>(
|
||||
var results = await connection.QueryAsync<SessionDto>(
|
||||
"session.ReadSession",
|
||||
commandType: System.Data.CommandType.StoredProcedure);
|
||||
return results.SingleOrDefault();
|
||||
|
||||
@@ -24,33 +24,14 @@ public class SessionRepository : ISessionRepository
|
||||
"session.CreateSession",
|
||||
new
|
||||
{
|
||||
SessionName = session.Name,
|
||||
InitialBoardStateDocument = initialBoardState,
|
||||
Player1Name = player1,
|
||||
InitialBoardStateDocument = initialBoardState
|
||||
},
|
||||
commandType: CommandType.StoredProcedure);
|
||||
}
|
||||
|
||||
public async Task ReadSession(string name)
|
||||
{
|
||||
using var connection = new SqlConnection(connectionString);
|
||||
var results = await connection.QueryAsync<SessionDto>(
|
||||
"session.ReadSession",
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
if (!results.Any())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var dto = results.First();
|
||||
return new Session(
|
||||
name: dto.Name,
|
||||
initialState: JsonSerializer.Deserialize< dto.BoardState)
|
||||
}
|
||||
}
|
||||
|
||||
public interface ISessionRepository
|
||||
{
|
||||
Task CreateSession(ShogiBoard session);
|
||||
Task CreateSession(ShogiBoard session, string player1);
|
||||
}
|
||||
Reference in New Issue
Block a user