Merge branch 'master' of https://bitbucket.org/Hauth/shogi
This commit is contained in:
@@ -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")]
|
[HttpPatch("{sessionName}/Move")]
|
||||||
public async Task<IActionResult> Move([FromRoute] string sessionName, [FromBody] MovePieceCommand command)
|
public async Task<IActionResult> Move([FromRoute] string sessionName, [FromBody] MovePieceCommand command)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ public class Session
|
|||||||
public void AddPlayer2(string player2Name)
|
public void AddPlayer2(string player2Name)
|
||||||
{
|
{
|
||||||
if (Player2 != null) throw new InvalidOperationException("Player 2 already exists while trying to add a second player.");
|
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;
|
Player2 = player2Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user