Replace custom socket implementation with SignalR.
Replace MSAL and custom cookie auth with Microsoft.Identity.EntityFramework Also some UI redesign to accommodate different login experience.
This commit is contained in:
@@ -1,65 +1,24 @@
|
||||
using Dapper;
|
||||
using Shogi.Contracts.Api;
|
||||
using Shogi.Contracts.Types;
|
||||
using Shogi.Api.Repositories.Dto;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
namespace Shogi.Api.Repositories;
|
||||
|
||||
public class QueryRepository : IQueryRespository
|
||||
public class QueryRepository(IConfiguration configuration)
|
||||
{
|
||||
private readonly string connectionString;
|
||||
private readonly string connectionString = configuration.GetConnectionString("ShogiDatabase")
|
||||
?? throw new InvalidOperationException("No database configured for QueryRepository.");
|
||||
|
||||
public QueryRepository(IConfiguration configuration)
|
||||
{
|
||||
var connectionString = configuration.GetConnectionString("ShogiDatabase") ?? throw new InvalidOperationException("No database configured for QueryRepository.");
|
||||
this.connectionString = connectionString;
|
||||
}
|
||||
public async Task<IEnumerable<SessionDto>> ReadSessionsMetadata(string playerId)
|
||||
{
|
||||
using var connection = new SqlConnection(this.connectionString);
|
||||
|
||||
public async Task<ReadSessionsPlayerCountResponse> ReadSessionPlayerCount(string playerName)
|
||||
{
|
||||
using var connection = new SqlConnection(connectionString);
|
||||
var results = await connection.QueryMultipleAsync(
|
||||
"session.ReadSessionsMetadata",
|
||||
new { PlayerId = playerId },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
var results = await connection.QueryMultipleAsync(
|
||||
"session.ReadSessionPlayerCount",
|
||||
new { PlayerName = playerName },
|
||||
commandType: System.Data.CommandType.StoredProcedure);
|
||||
|
||||
var joinedSessions = await results.ReadAsync<SessionMetadata>();
|
||||
var otherSessions = await results.ReadAsync<SessionMetadata>();
|
||||
return new ReadSessionsPlayerCountResponse
|
||||
{
|
||||
PlayerHasJoinedSessions = joinedSessions.ToList(),
|
||||
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;
|
||||
}
|
||||
return await results.ReadAsync<SessionDto>();
|
||||
}
|
||||
}
|
||||
|
||||
public interface IQueryRespository
|
||||
{
|
||||
Task<(User Player1, User? Player2)?> GetUsersForSession(string sessionName);
|
||||
Task<ReadSessionsPlayerCountResponse> ReadSessionPlayerCount(string playerName);
|
||||
}
|
||||
Reference in New Issue
Block a user