Skip to content

Commit

Permalink
[FIX] #232 admin 게임 관리 페이지에서 점수 수정 시 승패 수정 안되는 문제 (#467)
Browse files Browse the repository at this point in the history
  • Loading branch information
AYoungSn authored Jan 2, 2024
1 parent 6938397 commit 904317e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public void rankResultEdit(RankGamePPPModifyReqDto reqDto, Long gameId) {
pChangeAdminRepository.delete(pChanges.get(0));
}
rankRedisService.updateRankRedis(teamUsers.get(0), teamUsers.get(1), game);
rankRedisService.updateAllTier(gameId);
}

private void rollbackGameResult(RankGamePPPModifyReqDto reqDto, Season season, TeamUser teamUser, List<PChange> pChanges) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,17 @@ public void updatePPP(TeamUser teamuser, RankRedis myTeam, int enemyScore, Integ
Rank rank = rankRepository.findByUserIdAndSeasonId(myTeam.getUserId(), seasonId)
.orElseThrow(() -> new NotExistException("rank 정보가 없습니다.", ErrorCode.NOT_FOUND));
Integer changedPpp = EloRating.pppChange(myPPP, enemyPPP,
teamuser.getTeam().getWin(), Math.abs(teamuser.getTeam().getScore() - enemyScore) == 2);
teamuser.getTeam().getWin(),
Math.abs(teamuser.getTeam().getScore() - enemyScore) == 2);
log.info("update before: intraId: " + teamuser.getUser().getIntraId() + ", win: db(" + rank.getWins()
+ "), redis(" + myTeam.getWins() + "), losses: db(" + rank.getLosses()
+ "), redis(" + myTeam.getLosses() + ")");
rank.modifyUserRank(rank.getPpp() + changedPpp, win, losses);

myTeam.updateRank(changedPpp,
win, losses);

log.info("update after: intraId: " + teamuser.getUser().getIntraId() + ", win: db(" + rank.getWins()
+ "), redis(" + myTeam.getWins() + "), losses: db(" + rank.getLosses()
+ "), redis(" + myTeam.getLosses() + ")");
}

@Transactional
Expand Down Expand Up @@ -130,11 +135,15 @@ public void rollbackRank(TeamUser teamUser, int ppp, Long seasonId) {
int losses = !teamUser.getTeam().getWin() ? myTeam.getLosses() - 1: myTeam.getLosses();
Rank rank = rankRepository.findByUserIdAndSeasonId(myTeam.getUserId(), seasonId)
.orElseThrow(RankNotFoundException::new);
log.info("Before: userId: " + teamUser.getUser().getIntraId() + ", " + "ppp: rank(" + rank.getPpp() + "), redis(" + myTeam.getPpp() + ")");
log.info("Before: userId: " + teamUser.getUser().getIntraId() + ", " + "ppp: rank("
+ rank.getPpp() + "), redis(" + myTeam.getPpp() + "), win: " + myTeam.getWins()
+ ", losses: " + myTeam.getLosses());
rank.modifyUserRank(ppp, win, losses);
myTeam.changedRank(ppp, win, losses);
rankRepository.flush();
updateRankUser(hashkey, RedisKeyManager.getZSetKey(seasonId), teamUser.getUser().getId(), myTeam);
log.info("After: userId: " + teamUser.getUser().getIntraId() + ", " + "ppp: rank(" + rank.getPpp() + "), redis(" + myTeam.getPpp() + ")");
log.info("After: userId: " + teamUser.getUser().getIntraId() + ", " + "ppp: rank("
+ rank.getPpp() + "), redis(" + myTeam.getPpp() + "), win: " + myTeam.getWins()
+ ", losses: " + myTeam.getLosses());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,16 @@ void getUserGameListEndPage() throws Exception {
gameService.createRankResult(rankResultReqDto, adminUserId);

Rank adminUserRank = rankRepository.findByUserIdAndSeasonId(adminUserId, season.getId()).get();
Rank enemyUser1Rank = rankRepository.findByUserIdAndSeasonId(enemyUser1.getId(), season.getId()).get();
System.out.println("MANGO ADMIN1 before DB PPP : " + adminUserRank.getPpp());
System.out.println("MANGO ENEMY1 before DB PPP : " + enemyUser1Rank.getPpp());

Rank enemyUser1Rank = rankRepository.findByUserIdAndSeasonId(enemyUser1.getId(),
season.getId()).get();
// win 1, losses 0, ppp 1020
// System.out.println("MANGO ADMIN1 before DB PPP : " + adminUserRank.getPpp());
assertThat(adminUserRank.getLosses()).isEqualTo(0);
assertThat(adminUserRank.getWins()).isEqualTo(1);
// win 0, losses 1, ppp 982
// System.out.println("MANGO ENEMY1 before DB PPP : " + enemyUser1Rank.getPpp());
assertThat(enemyUser1Rank.getWins()).isEqualTo(0);
assertThat(enemyUser1Rank.getLosses()).isEqualTo(1);

RankGamePPPModifyReqDto modifyReqDto = new RankGamePPPModifyReqDto(game1Info.getMyTeamId(), 1, game1Info.getEnemyTeamId(), 0);
mockMvc.perform(put("/pingpong/admin/games/" + game1Info.getGameId())
Expand All @@ -198,10 +204,18 @@ void getUserGameListEndPage() throws Exception {
GameTeamUser historyGame1 = gameRepository.findTeamsByGameIsIn(List.of(game1Info.getGameId())).get(0);

adminUserRank = rankRepository.findByUserIdAndSeasonId(adminUserId, season.getId()).get();
enemyUser1Rank = rankRepository.findByUserIdAndSeasonId(enemyUser1.getId(), season.getId()).get();
System.out.println("MANGO ADMIN1 after DB PPP : " + adminUserRank.getPpp());
System.out.println("MANGO ENEMY1 after DB PPP : " + enemyUser1Rank.getPpp());

enemyUser1Rank = rankRepository.findByUserIdAndSeasonId(enemyUser1.getId(), season.getId())
.get();
// win 1, losses 0, ppp 1020
// MANGO ADMIN1 after DB
assertThat(adminUserRank.getPpp()).isEqualTo(1020);
assertThat(adminUserRank.getWins()).isEqualTo(1);
assertThat(adminUserRank.getLosses()).isEqualTo(0);
// win 0, losses 1, ppp 982
// MANGO ENEMY1 after DB
assertThat(enemyUser1Rank.getWins()).isEqualTo(0);
assertThat(enemyUser1Rank.getLosses()).isEqualTo(1);
assertThat(enemyUser1Rank.getPpp()).isEqualTo(982);
//////////////////////////////
sleep(1000);
//////////////////////////////
Expand All @@ -216,12 +230,20 @@ void getUserGameListEndPage() throws Exception {
gameService.createRankResult(rankResultReqDto, adminUserId);

adminUserRank = rankRepository.findByUserIdAndSeasonId(adminUserId, season.getId()).get();
Rank enemyUser2Rank = rankRepository.findByUserIdAndSeasonId(enemyUser2.getId(), season.getId()).get();
System.out.println("MANGO ADMIN2 before DB PPP : " + adminUserRank.getPpp());
System.out.println("MANGO ENEMY2 before DB PPP : " + enemyUser2Rank.getPpp());


modifyReqDto = new RankGamePPPModifyReqDto(game2Info.getMyTeamId(), 0, game2Info.getEnemyTeamId(), 1);
Rank enemyUser2Rank = rankRepository.findByUserIdAndSeasonId(enemyUser2.getId(),
season.getId()).get();
// win 1, losses 1, ppp 1001
// MANGO ADMIN2 before DB
assertThat(adminUserRank.getWins()).isEqualTo(1);
assertThat(adminUserRank.getLosses()).isEqualTo(1);
assertThat(adminUserRank.getPpp()).isEqualTo(1001);
// win1, losses 0, ppp 1021
// MANGO ENEMY2 before DB
assertThat(enemyUser2Rank.getWins()).isEqualTo(1);
assertThat(enemyUser2Rank.getLosses()).isEqualTo(0);
assertThat(enemyUser2Rank.getPpp()).isEqualTo(1021);

modifyReqDto = new RankGamePPPModifyReqDto(game2Info.getMyTeamId(), 2, game2Info.getEnemyTeamId(), 1);
mockMvc.perform(put("/pingpong/admin/games/" + game2Info.getGameId())
.content(objectMapper.writeValueAsString(modifyReqDto))
.contentType(MediaType.APPLICATION_JSON)
Expand All @@ -231,7 +253,17 @@ void getUserGameListEndPage() throws Exception {

adminUserRank = rankRepository.findByUserIdAndSeasonId(adminUserId, season.getId()).get();
enemyUser2Rank = rankRepository.findByUserIdAndSeasonId(enemyUser2.getId(), season.getId()).get();
System.out.println("MANGO ADMIN2 after DB PPP : " + adminUserRank.getPpp());
System.out.println("MANGO ENEMY2 after DB PPP : " + enemyUser2Rank.getPpp());
// win 2, losses 0, ppp 1038
// System.out.println("MANGO ADMIN2 after DB PPP : " + adminUserRank.getPpp() + ", WIN: "
// + adminUserRank.getWins() + ", LOSSES" + adminUserRank.getLosses());
assertThat(adminUserRank.getWins()).isEqualTo(2);
assertThat(adminUserRank.getLosses()).isEqualTo(0);
assertThat(adminUserRank.getPpp()).isEqualTo(1038);
// win 0, losses 1, ppp
System.out.println("MANGO ENEMY2 after DB PPP : " + enemyUser2Rank.getPpp() + ", WIN: "
+ enemyUser2Rank.getWins() + ", LOSSES" + enemyUser2Rank.getLosses());
assertThat(enemyUser2Rank.getWins()).isEqualTo(0);
assertThat(enemyUser2Rank.getLosses()).isEqualTo(1);
// assertThat(enemyUser2Rank.getPpp()).isEqualTo()
}
}

0 comments on commit 904317e

Please sign in to comment.