diff --git a/Shogi.Database/Session/Stored Procedures/CreateSession.sql b/Shogi.Database/Session/Stored Procedures/CreateSession.sql
index 78cc9a8..b40d6aa 100644
--- a/Shogi.Database/Session/Stored Procedures/CreateSession.sql
+++ b/Shogi.Database/Session/Stored Procedures/CreateSession.sql
@@ -1,14 +1,14 @@
CREATE PROCEDURE [session].[CreateSession]
- @InitialBoardStateDocument [session].[JsonDocument]
+ @InitialBoardStateDocument [session].[JsonDocument],
+ @Player1Name [user].[UserName]
AS
BEGIN
SET NOCOUNT ON
- INSERT INTO [session].[Session] ([Name], BoardState, Player1Id)
+ INSERT INTO [session].[Session] (BoardState, Player1Id)
SELECT
- JSON_VALUE(@InitialBoardStateDocument, '$.Name'),
@InitialBoardStateDocument,
Id
FROM [user].[User]
- WHERE [Name] = JSON_VALUE(@InitialBoardStateDocument, '$.Player1');
+ WHERE [Name] = @Player1Name
END
\ No newline at end of file
diff --git a/Shogi.Database/Session/Stored Procedures/ReadSession.sql b/Shogi.Database/Session/Stored Procedures/ReadSession.sql
index 5bf4d8c..5cece40 100644
--- a/Shogi.Database/Session/Stored Procedures/ReadSession.sql
+++ b/Shogi.Database/Session/Stored Procedures/ReadSession.sql
@@ -6,7 +6,6 @@ BEGIN
SELECT
sess.[Name],
- GameOver,
BoardState,
p1.[Name] as Player1,
p2.[Name] as Player2
diff --git a/Shogi.Database/Session/Tables/Session.sql b/Shogi.Database/Session/Tables/Session.sql
index 0497464..17ba415 100644
--- a/Shogi.Database/Session/Tables/Session.sql
+++ b/Shogi.Database/Session/Tables/Session.sql
@@ -2,12 +2,12 @@
(
Id BIGINT NOT NULL PRIMARY KEY IDENTITY,
Created DATETIMEOFFSET NOT NULL DEFAULT SYSDATETIMEOFFSET(),
- DomainDocument [session].[JsonDocument] NOT NULL,
- [Name] AS JSON_VALUE(DomainDocument, '$.Name') UNIQUE,
Player1Id BIGINT NOT NULL,
Player2Id BIGINT NULL,
+ BoardState [session].[JsonDocument] NOT NULL,
+ [Name] AS JSON_VALUE(BoardState, '$.Name') UNIQUE,
- CONSTRAINT [BoardState must be json] CHECK (isjson(DomainDocument)=1),
+ CONSTRAINT [BoardState must be json] CHECK (isjson(BoardState)=1),
CONSTRAINT FK_Player1_User FOREIGN KEY (Player1Id) REFERENCES [user].[User] (Id)
ON DELETE CASCADE
ON UPDATE CASCADE,
diff --git a/Shogi.Sockets/Repositories/Dto/SessionDto.cs b/Shogi.Sockets/Repositories/Dto/SessionDto.cs
index 7b70d5b..c0aef66 100644
--- a/Shogi.Sockets/Repositories/Dto/SessionDto.cs
+++ b/Shogi.Sockets/Repositories/Dto/SessionDto.cs
@@ -1,5 +1,8 @@
namespace Shogi.Api.Repositories.Dto
{
+ ///
+ /// Useful with Dapper to read from database.
+ ///
public class SessionDto
{
public string Name { get; set; }
diff --git a/Shogi.Sockets/Repositories/QueryRepository.cs b/Shogi.Sockets/Repositories/QueryRepository.cs
index ca336dd..0be7b4d 100644
--- a/Shogi.Sockets/Repositories/QueryRepository.cs
+++ b/Shogi.Sockets/Repositories/QueryRepository.cs
@@ -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 ReadSession(string name)
{
using var connection = new SqlConnection(connectionString);
- var results = await connection.QueryAsync(
+ var results = await connection.QueryAsync(
"session.ReadSession",
commandType: System.Data.CommandType.StoredProcedure);
return results.SingleOrDefault();
diff --git a/Shogi.Sockets/Repositories/SessionRepository.cs b/Shogi.Sockets/Repositories/SessionRepository.cs
index d7e2d9e..e1e2a83 100644
--- a/Shogi.Sockets/Repositories/SessionRepository.cs
+++ b/Shogi.Sockets/Repositories/SessionRepository.cs
@@ -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(
- "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);
}
\ No newline at end of file