Skip to content

Commit

Permalink
[TEST] #232 foreach -> fori
Browse files Browse the repository at this point in the history
  • Loading branch information
AYoungSn committed Jan 24, 2024
1 parent 704b00d commit edef83d
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,21 +134,19 @@ public void rankResultEdit(RankGamePPPModifyReqDto reqDto, Long gameId) {
throw new NotRecentlyGameException();
}
// pchange 가져와서 rank ppp 이전 값을 가지고 새 점수를 바탕으로 다시 계산
for (TeamUser teamUser :
teamUsers) {
List<PChange> pChanges = pChangeAdminRepository.findByTeamUser(teamUser.getUser().getId());
for (int i = 0; i < teamUsers.size(); i++) {
List<PChange> pChanges = pChangeAdminRepository.findByTeamUser(teamUsers.get(i).getUser().getId());
if (!pChanges.get(0).getGame().getId().equals(gameId)) {
throw new PChangeNotExistException();
}
rollbackGameResult(season, teamUser, pChanges);
rollbackGameResult(season, teamUsers.get(i), pChanges);
pChangeAdminRepository.deleteById(pChanges.get(0).getId());
entityManager.flush();
}
for (TeamUser teamUser :
teamUsers) {
updateScore(reqDto, teamUser);
for (int i = 0; i < teamUsers.size(); i++) {
updateScore(reqDto, teamUsers.get(i));
}
entityManager.flush();
entityManager.clear();
teamUserAdminRepository.flush();
rankRedisService.updateRankRedis(teamUsers.get(0), teamUsers.get(1), game);
tierService.updateAllTier(game.getSeason());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public interface TeamUserAdminRepository extends JpaRepository<TeamUser, Long> {
@Query("SELECT tu.user FROM TeamUser tu WHERE tu.team.id = :teamId")
List<User> findUsersByTeamId(@Param("teamId") Long teamId);

@Query("SELECT tu FROM TeamUser tu JOIN FETCH tu.team t JOIN FETCH tu.user WHERE tu.team.id IN (:teamId) AND t.id = tu.team.id")
@Query("SELECT tu FROM TeamUser tu JOIN FETCH tu.team t JOIN FETCH tu.user WHERE tu.team.id IN (:teamId)")
List<TeamUser> findUsersByTeamIdIn(@Param("teamId") List<Long> teamId);
}
3 changes: 3 additions & 0 deletions src/main/java/com/gg/server/domain/game/data/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
import java.util.List;
import java.util.Optional;

import org.hibernate.annotations.DynamicUpdate;

@NoArgsConstructor
@AllArgsConstructor
@Getter
@Entity
@DynamicUpdate
public class Game {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/gg/server/domain/rank/data/Rank.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
import javax.validation.constraints.NotNull;
import java.io.Serializable;

import org.hibernate.annotations.DynamicUpdate;

@Entity
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name="ranks")
@DynamicUpdate
public class Rank extends BaseTimeEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void updatePPP(TeamUser teamuser, RankRedis myTeam, int enemyScore, Integ
+ "), redis(" + myTeam.getWins() + "), losses: db(" + rank.getLosses()
+ "), redis(" + myTeam.getLosses() + ")");
rank.modifyUserRank(rank.getPpp() + changedPpp, win, losses);
rankRepository.updateByUserIdAndSeasonId(rank.getUser().getId(), seasonId, rank.getPpp(), win, losses);
// rankRepository.updateByUserIdAndSeasonId(rank.getUser().getId(), seasonId, rank.getPpp(), win, losses);
myTeam.updateRank(changedPpp,
win, losses);
log.info("update after: intraId: " + teamuser.getUser().getIntraId() + ", win: db(" + rank.getWins()
Expand Down Expand Up @@ -148,7 +148,7 @@ public void rollbackRank(TeamUser teamUser, int ppp, Long seasonId) {
rank.modifyUserRank(ppp, win, losses);
myTeam.changedRank(ppp, win, losses);
updateRankUser(hashkey, RedisKeyManager.getZSetKey(seasonId), teamUser.getUser().getId(), myTeam);
rankRepository.updateByUserIdAndSeasonId(rank.getUser().getId(), seasonId, ppp, win, losses);
// rankRepository.updateByUserIdAndSeasonId(rank.getUser().getId(), seasonId, ppp, win, losses);
log.info("After: userId: " + teamUser.getUser().getIntraId() + ", " + "ppp: rank("
+ rank.getPpp() + "), redis(" + myTeam.getPpp() + "), win: " + myTeam.getWins()
+ ", losses: " + myTeam.getLosses());
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/gg/server/domain/team/data/Team.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.DynamicUpdate;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -24,6 +27,7 @@
@AllArgsConstructor
@Entity
@Getter
@DynamicUpdate
public class Team {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/gg/server/domain/user/data/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
import javax.validation.constraints.NotNull;
import java.io.Serializable;

import org.hibernate.annotations.DynamicUpdate;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@DynamicUpdate
public class User extends BaseTimeEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down

0 comments on commit edef83d

Please sign in to comment.