mapper class and delete old stuff
This commit is contained in:
@@ -7,68 +7,68 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Gameboard.ShogiUI.Sockets.Managers
|
||||
{
|
||||
public interface IGameboardManager
|
||||
{
|
||||
Task<bool> AssignPlayer2ToSession(string sessionName, User user);
|
||||
Task<User?> ReadUser(ClaimsPrincipal user);
|
||||
Task<bool> CreateUser(ClaimsPrincipal user);
|
||||
}
|
||||
public interface IGameboardManager
|
||||
{
|
||||
Task AssignPlayer2ToSession(string sessionName, User user);
|
||||
Task<User?> ReadUser(ClaimsPrincipal user);
|
||||
Task<User?> CreateUser(ClaimsPrincipal user);
|
||||
}
|
||||
|
||||
public class GameboardManager : IGameboardManager
|
||||
{
|
||||
private readonly IGameboardRepository repository;
|
||||
public class GameboardManager : IGameboardManager
|
||||
{
|
||||
private readonly IGameboardRepository repository;
|
||||
|
||||
public GameboardManager(IGameboardRepository repository)
|
||||
{
|
||||
this.repository = repository;
|
||||
}
|
||||
public GameboardManager(IGameboardRepository repository)
|
||||
{
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
public Task<bool> CreateUser(ClaimsPrincipal principal)
|
||||
{
|
||||
var id = principal.UserId();
|
||||
if (string.IsNullOrEmpty(id))
|
||||
{
|
||||
return Task.FromResult(false);
|
||||
}
|
||||
public async Task<User> CreateUser(ClaimsPrincipal principal)
|
||||
{
|
||||
var id = principal.UserId();
|
||||
if (string.IsNullOrEmpty(id))
|
||||
{
|
||||
throw new InvalidOperationException("Cannot create user from given claims.");
|
||||
}
|
||||
|
||||
var user = principal.IsGuest()
|
||||
? User.CreateGuestUser(id)
|
||||
: User.CreateMsalUser(id);
|
||||
var user = principal.IsGuest()
|
||||
? User.CreateGuestUser(id)
|
||||
: User.CreateMsalUser(id);
|
||||
|
||||
return repository.CreateUser(user);
|
||||
}
|
||||
await repository.CreateUser(user);
|
||||
return user;
|
||||
}
|
||||
|
||||
public Task<User?> ReadUser(ClaimsPrincipal principal)
|
||||
{
|
||||
var userId = principal.UserId();
|
||||
if (!string.IsNullOrEmpty(userId))
|
||||
{
|
||||
return repository.ReadUser(userId);
|
||||
}
|
||||
public Task<User?> ReadUser(ClaimsPrincipal principal)
|
||||
{
|
||||
var userId = principal.UserId();
|
||||
if (!string.IsNullOrEmpty(userId))
|
||||
{
|
||||
return repository.ReadUser(userId);
|
||||
}
|
||||
|
||||
return Task.FromResult<User?>(null);
|
||||
}
|
||||
return Task.FromResult<User?>(null);
|
||||
}
|
||||
|
||||
|
||||
public async Task<string> CreateJoinCode(string sessionName, string playerName)
|
||||
{
|
||||
//var session = await repository.GetGame(sessionName);
|
||||
//if (playerName == session?.Player1)
|
||||
//{
|
||||
// return await repository.PostJoinCode(sessionName, playerName);
|
||||
//}
|
||||
return string.Empty;
|
||||
}
|
||||
public async Task<string> CreateJoinCode(string sessionName, string playerName)
|
||||
{
|
||||
//var session = await repository.GetGame(sessionName);
|
||||
//if (playerName == session?.Player1)
|
||||
//{
|
||||
// return await repository.PostJoinCode(sessionName, playerName);
|
||||
//}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public async Task<bool> AssignPlayer2ToSession(string sessionName, User user)
|
||||
{
|
||||
var session = await repository.ReadSessionMetaData(sessionName);
|
||||
if (session != null && !session.IsPrivate && session.Player2 == null)
|
||||
{
|
||||
session.SetPlayer2(user);
|
||||
return await repository.UpdateSession(session);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public async Task AssignPlayer2ToSession(string sessionName, User user)
|
||||
{
|
||||
var session = await repository.ReadSessionMetaData(sessionName);
|
||||
if (session != null && !session.IsPrivate && session.Player2 == null)
|
||||
{
|
||||
session.SetPlayer2(user.Id);
|
||||
await repository.UpdateSession(session);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user