diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeReader.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeReader.java index 672a4eb..1cde291 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeReader.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeReader.java @@ -10,7 +10,7 @@ public interface UserChallengeReader { UserChallenge getByIdWithVerificationAndChallenge(Long id); - UserChallenge getByChallengeIdWithVerificationAndChallenge(Long challengeId); + UserChallenge getByChallengeIdWithVerificationAndChallenge(Long challengeId, Long userId); Optional findById(Long id); diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeService.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeService.java index 067287a..b08ddf7 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeService.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/userchallenge/UserChallengeService.java @@ -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("해당 챌린지에 참여한 유저가 아닙니다."); } diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/userchallenge/UserChallengeReaderImpl.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/userchallenge/UserChallengeReaderImpl.java index 1b259b4..e99713d 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/userchallenge/UserChallengeReaderImpl.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/userchallenge/UserChallengeReaderImpl.java @@ -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); } diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/userchallenge/UserChallengeRepository.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/userchallenge/UserChallengeRepository.java index 8abc170..527eb46 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/userchallenge/UserChallengeRepository.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/infrastructure/challengegroup/userchallenge/UserChallengeRepository.java @@ -22,6 +22,10 @@ public interface UserChallengeRepository extends JpaRepository findByChallengeIdWithFetchLazy(@Param("challengeId") Long challengeId); + "WHERE uc.challenge.id = :challengeId " + + "AND uc.user.id = :userId") + Optional findByChallengeIdWithFetchLazy( + @Param("challengeId") Long challengeId, + @Param("userId") Long userId + ); }