From ae1c1c7192723e2b06ecd4d15a0b60c0988c1919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=90=ED=99=8D=EC=84=9D?= <78216059+bayy1216@users.noreply.github.com> Date: Sun, 2 Jun 2024 03:42:12 +0900 Subject: [PATCH] [Feat] fix --- .../challengegroup/userchallenge/UserChallengeReader.java | 2 +- .../userchallenge/UserChallengeService.java | 2 +- .../userchallenge/UserChallengeReaderImpl.java | 4 ++-- .../userchallenge/UserChallengeRepository.java | 8 ++++++-- 4 files changed, 10 insertions(+), 6 deletions(-) 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 + ); }