yep
This commit is contained in:
@@ -68,7 +68,7 @@ public class SessionsController : ControllerBase
|
||||
return this.NoContent();
|
||||
}
|
||||
|
||||
return this.Forbid("Cannot delete sessions created by others.");
|
||||
return this.StatusCode(StatusCodes.Status403Forbidden, "Cannot delete sessions created by others.");
|
||||
}
|
||||
|
||||
[HttpGet("PlayerCount")]
|
||||
@@ -108,15 +108,15 @@ public class SessionsController : ControllerBase
|
||||
};
|
||||
}
|
||||
|
||||
[HttpPatch("{name}/Move")]
|
||||
public async Task<IActionResult> Move([FromRoute] string name, [FromBody] MovePieceCommand command)
|
||||
[HttpPatch("{sessionName}/Move")]
|
||||
public async Task<IActionResult> Move([FromRoute] string sessionName, [FromBody] MovePieceCommand command)
|
||||
{
|
||||
var userId = User.GetShogiUserId();
|
||||
var session = await sessionRepository.ReadSession(name);
|
||||
var session = await sessionRepository.ReadSession(sessionName);
|
||||
|
||||
if (session == null) return this.NotFound("Shogi session does not exist.");
|
||||
|
||||
if (!session.IsSeated(userId)) return this.Forbid("Player is not a member of the Shogi session.");
|
||||
if (!session.IsSeated(userId)) return this.StatusCode(StatusCodes.Status403Forbidden, "Player is not a member of the Shogi session.");
|
||||
|
||||
try
|
||||
{
|
||||
@@ -126,14 +126,14 @@ public class SessionsController : ControllerBase
|
||||
}
|
||||
else
|
||||
{
|
||||
session.Board.Move(command.From!, command.To, command.IsPromotion!.Value);
|
||||
session.Board.Move(command.From!, command.To, command.IsPromotion ?? false);
|
||||
}
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
catch (InvalidOperationException e)
|
||||
{
|
||||
return this.Conflict("Move is illegal.");
|
||||
return this.Conflict(e.Message);
|
||||
}
|
||||
// TODO: sessionRespository.SaveMove();
|
||||
await sessionRepository.CreateMove(sessionName, command);
|
||||
await communicationManager.BroadcastToPlayers(
|
||||
new PlayerHasMovedMessage
|
||||
{
|
||||
@@ -145,73 +145,4 @@ public class SessionsController : ControllerBase
|
||||
|
||||
return this.NoContent();
|
||||
}
|
||||
|
||||
//[HttpPost("{sessionName}/Move")]
|
||||
//public async Task<IActionResult> MovePiece([FromRoute] string sessionName, [FromBody] MovePieceCommand request)
|
||||
//{
|
||||
|
||||
// var user = await gameboardManager.ReadUser(User);
|
||||
// var session = await gameboardRepository.ReadSession(sessionName);
|
||||
// if (session == null)
|
||||
// {
|
||||
// return NotFound();
|
||||
// }
|
||||
// if (user == null || (session.Player1 != user.Id && session.Player2 != user.Id))
|
||||
// {
|
||||
// return Forbid("User is not seated at this game.");
|
||||
// }
|
||||
|
||||
// try
|
||||
// {
|
||||
// var move = request.Move;
|
||||
// if (move.PieceFromCaptured.HasValue)
|
||||
// session.Move(mapper.Map(move.PieceFromCaptured.Value), move.To);
|
||||
// else if (!string.IsNullOrWhiteSpace(move.From))
|
||||
// session.Move(move.From, move.To, move.IsPromotion);
|
||||
|
||||
// await gameboardRepository.CreateBoardState(session);
|
||||
// await communicationManager.BroadcastToPlayers(
|
||||
// new MoveResponse
|
||||
// {
|
||||
// SessionName = session.Name,
|
||||
// PlayerName = user.Id
|
||||
// },
|
||||
// session.Player1,
|
||||
// session.Player2);
|
||||
|
||||
// return Ok();
|
||||
// }
|
||||
// catch (InvalidOperationException ex)
|
||||
// {
|
||||
// return Conflict(ex.Message);
|
||||
// }
|
||||
//}
|
||||
|
||||
//[HttpPut("{sessionName}")]
|
||||
//public async Task<IActionResult> PutJoinSession([FromRoute] string sessionName)
|
||||
//{
|
||||
// var user = await ReadUserOrThrow();
|
||||
// var session = await gameboardRepository.ReadSessionMetaData(sessionName);
|
||||
// if (session == null)
|
||||
// {
|
||||
// return NotFound();
|
||||
// }
|
||||
// if (session.Player2 != null)
|
||||
// {
|
||||
// return this.Conflict("This session already has two seated players and is full.");
|
||||
// }
|
||||
|
||||
// session.SetPlayer2(user.Id);
|
||||
// await gameboardRepository.UpdateSession(session);
|
||||
|
||||
// var opponentName = user.Id == session.Player1
|
||||
// ? session.Player2!
|
||||
// : session.Player1;
|
||||
// await communicationManager.BroadcastToPlayers(new JoinSessionResponse
|
||||
// {
|
||||
// SessionName = session.Name,
|
||||
// PlayerName = user.Id
|
||||
// }, opponentName);
|
||||
// return Ok();
|
||||
//}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user