This commit is contained in:
2022-11-14 20:01:06 -06:00
parent 716470f24d
commit 03c02cceae
2 changed files with 148 additions and 135 deletions

View File

@@ -108,6 +108,18 @@ public class SessionsController : ControllerBase
};
}
[HttpPut("{name}/Join")]
public async Task<IActionResult> JoinSession(string name)
{
var session = await sessionRepository.ReadSession(name);
if (session == null) return this.NotFound();
if (string.IsNullOrEmpty(session.Player2))
{
session.AddPlayer2(User.GetShogiUserId());
}
}
[HttpPatch("{sessionName}/Move")]
public async Task<IActionResult> Move([FromRoute] string sessionName, [FromBody] MovePieceCommand command)
{

View File

@@ -21,6 +21,7 @@ public class Session
public void AddPlayer2(string player2Name)
{
if (Player2 != null) throw new InvalidOperationException("Player 2 already exists while trying to add a second player.");
if (Player1.Equals(player2Name, StringComparison.OrdinalIgnoreCase)) throw new InvalidOperationException("Player 2 must be different from Player 1");
Player2 = player2Name;
}