Skip to content

Commit 6bf81a8

Browse files
authored
Merge pull request #233 from 42organization/fix/점수입력오류수정
[fix] 점수 입력 시 game table에 배타락 추가
2 parents cf8e922 + fcf5a3a commit 6bf81a8

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/main/java/com/gg/server/domain/game/data/GameRepository.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
import java.util.Optional;
88

99
import com.gg.server.domain.team.dto.GameUser;
10+
import javax.persistence.LockModeType;
1011
import org.springframework.cache.annotation.Cacheable;
1112
import org.springframework.data.jpa.repository.JpaRepository;
1213
import com.gg.server.domain.game.dto.GameTeamUser;
1314
import org.springframework.data.domain.Pageable;
1415
import org.springframework.data.domain.Slice;
16+
import org.springframework.data.jpa.repository.Lock;
1517
import org.springframework.data.jpa.repository.Query;
1618
import org.springframework.data.repository.query.Param;
1719

@@ -69,4 +71,7 @@ public interface GameRepository extends JpaRepository<Game, Long>, GameRepositor
6971
"team t, team_user tu, user u " +
7072
"WHERE g.id=t.game_id AND t.id = tu.team_id AND tu.user_id=u.id AND g.status = 'BEFORE'", nativeQuery = true)
7173
List<GameUser> findAllByStartTimeLessThanEqual(@Param("time") LocalDateTime time);
74+
@Lock(LockModeType.PESSIMISTIC_WRITE)
75+
@Query(value = "SELECT g FROM Game g WHERE g.id=:gamdId")
76+
Optional<Game> findWithPessimisticLockById(@Param("gameId") Long gameId);
7277
}

src/main/java/com/gg/server/domain/game/service/GameService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ public GameTeamInfo getUserGameInfo(Long gameId, Long userId) {
6060
})
6161
public Boolean createRankResult(RankResultReqDto scoreDto, Long userId) {
6262
// 현재 게임 id
63-
Game game = gameFindService.findByGameId(scoreDto.getGameId());
63+
Game game = gameRepository.findWithPessimisticLockById(scoreDto.getGameId())
64+
.orElseThrow(GameNotExistException::new);
6465
if (game.getStatus() != StatusType.WAIT && game.getStatus() != StatusType.LIVE) {
6566
return false;
6667
}

0 commit comments

Comments
 (0)