public async Task <PlayerInRoomDTO> LeaveRoom(LeaveRoomDTO leaveRoomDTO) { _logger.LogInformation("Player to leaving room: {@leaveRoomDTO}", leaveRoomDTO); var gameRoomPlayerData = await GetPlayerRoomData(leaveRoomDTO.GameRoomId, leaveRoomDTO.PlayerId); gameRoomPlayerData !.IsInRoom = false; // previously validated, never null await _repositoryGameRoomPlayer.Update(gameRoomPlayerData); var playerInRoomDTO = _mapper.Map <GameRoomPlayer, PlayerInRoomDTO>(gameRoomPlayerData); return(playerInRoomDTO); }
public async Task <ActionResult <PlayerInRoomDTO> > LeaveRoom(Guid gameRoomId, PlayerDTO playerDTO) { var leaveRoomDTO = new LeaveRoomDTO { GameRoomId = gameRoomId, PlayerId = playerDTO.PlayerId }; _logger.LogInformation("Leave room data received: {@leaveRoomDTO}", leaveRoomDTO); var validator = new PlayerPreviouslyInRoomValidator(_gameRoomServiceAsync, _playerServiceAsync); var validationResult = validator.Validate(leaveRoomDTO); if (!validationResult.IsValid) { return(BadRequest(validationResult.Errors)); } _logger.LogInformation("Validations were successfull, removing player from the room..."); var playerInRoomDTO = await _gameRoomServiceAsync.LeaveRoom(leaveRoomDTO); return(StatusCode(200, playerInRoomDTO)); }