Skip to content

Commit

Permalink
[Feat] fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bayy1216 committed Jun 1, 2024
1 parent 289dffd commit ae1c1c7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public interface UserChallengeReader {

UserChallenge getByIdWithVerificationAndChallenge(Long id);

UserChallenge getByChallengeIdWithVerificationAndChallenge(Long challengeId);
UserChallenge getByChallengeIdWithVerificationAndChallenge(Long challengeId, Long userId);

Optional<UserChallenge> findById(Long id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public ChallengeModel.ChallengeVerificationResult verification(
ChallengeCommand.VerificationCreate command
) {
UserChallenge userChallenge = userChallengeReader.getByChallengeIdWithVerificationAndChallenge(
challengeId);
challengeId, userId);
if(!userChallenge.getUser().getId().equals(userId)) {
throw new IllegalArgumentException("해당 챌린지에 참여한 유저가 아닙니다.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public UserChallenge getByIdWithVerificationAndChallenge(Long id) {
}

@Override
public UserChallenge getByChallengeIdWithVerificationAndChallenge(Long challengeId) {
public UserChallenge getByChallengeIdWithVerificationAndChallenge(Long challengeId, Long userId) {
return userChallengeRepository
.findByChallengeIdWithFetchLazy(challengeId)
.findByChallengeIdWithFetchLazy(challengeId, userId)
.orElseThrow(NoSuchElementException::new);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public interface UserChallengeRepository extends JpaRepository<UserChallenge, Lo
@Query("SELECT uc FROM UserChallenge uc " +
"LEFT JOIN FETCH uc.challengeVerifications " +
"LEFT JOIN FETCH uc.challenge " +
"WHERE uc.challenge.id = :challengeId")
Optional<UserChallenge> findByChallengeIdWithFetchLazy(@Param("challengeId") Long challengeId);
"WHERE uc.challenge.id = :challengeId " +
"AND uc.user.id = :userId")
Optional<UserChallenge> findByChallengeIdWithFetchLazy(
@Param("challengeId") Long challengeId,
@Param("userId") Long userId
);
}

0 comments on commit ae1c1c7

Please sign in to comment.