diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeController.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeController.java index 7f9126a..92a9c7d 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeController.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/challengegroup/challenge/ChallengeController.java @@ -45,17 +45,17 @@ public ApiResponse challengeParticipation( @ResponseStatus(HttpStatus.CREATED) @Operation(summary = "챌린지 인증", description = "챌린지에 인증한다.") - @PostMapping("/api/challenges/{userChallengeId}/verification") + @PostMapping("/api/challenges/{challengeId}/verification") public ApiResponse challengeVerification( @AuthenticationPrincipal JwtUser jwtUser, - @PathVariable Long userChallengeId, + @PathVariable Long challengeId, @RequestPart("body") ChallengeReq.ChallengeVerificationRequest request, @RequestPart("image") MultipartFile image ) { ChallengeCommand.Verificate command = request.toCommand(image); String imageUrl = imageUploader.upload(command.getImage()); ChallengeCommand.VerificationCreate afterUpload = command.afterUpload(imageUrl); - var model = userChallengeService.verification(userChallengeId, jwtUser.getId(), afterUpload); + var model = userChallengeService.verification(challengeId, jwtUser.getId(), afterUpload); var response = ChallengeRes.ChallengeVerificationResponse.from(model); return ApiResponse.success(response, "챌린지 인증에 성공하였습니다."); } 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 f55ebcd..672a4eb 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,6 +10,8 @@ public interface UserChallengeReader { UserChallenge getByIdWithVerificationAndChallenge(Long id); + UserChallenge getByChallengeIdWithVerificationAndChallenge(Long challengeId); + Optional findById(Long id); UserChallenge getByUserIdAndChallengeId(Long userId, Long challengeId); 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 1edf611..067287a 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 @@ -59,12 +59,12 @@ public void participateChallenge(Long userId, Long challengeId) { */ @Transactional public ChallengeModel.ChallengeVerificationResult verification( - Long userChallengeId, + Long challengeId, Long userId, ChallengeCommand.VerificationCreate command ) { - UserChallenge userChallenge = userChallengeReader.getByIdWithVerificationAndChallenge( - userChallengeId); + UserChallenge userChallenge = userChallengeReader.getByChallengeIdWithVerificationAndChallenge( + challengeId); 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 416ec70..1b259b4 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 @@ -35,6 +35,13 @@ public UserChallenge getByIdWithVerificationAndChallenge(Long id) { .orElseThrow(NoSuchElementException::new); } + @Override + public UserChallenge getByChallengeIdWithVerificationAndChallenge(Long challengeId) { + return userChallengeRepository + .findByChallengeIdWithFetchLazy(challengeId) + .orElseThrow(NoSuchElementException::new); + } + @Override public Optional findById(Long id) { return userChallengeRepository.findById(id); 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 777c9da..8abc170 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 @@ -19,4 +19,9 @@ public interface UserChallengeRepository extends JpaRepository findByIdWithFetchLazy(@Param("id") Long id); + @Query("SELECT uc FROM UserChallenge uc " + + "LEFT JOIN FETCH uc.challengeVerifications " + + "LEFT JOIN FETCH uc.challenge " + + "WHERE uc.challenge.id = :challengeId") + Optional findByChallengeIdWithFetchLazy(@Param("challengeId") Long challengeId); }