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 db9de54 commit 289dffd
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ public ApiResponse<Void> challengeParticipation(

@ResponseStatus(HttpStatus.CREATED)
@Operation(summary = "챌린지 인증", description = "챌린지에 인증한다.")
@PostMapping("/api/challenges/{userChallengeId}/verification")
@PostMapping("/api/challenges/{challengeId}/verification")
public ApiResponse<ChallengeRes.ChallengeVerificationResponse> 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, "챌린지 인증에 성공하였습니다.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public interface UserChallengeReader {

UserChallenge getByIdWithVerificationAndChallenge(Long id);

UserChallenge getByChallengeIdWithVerificationAndChallenge(Long challengeId);

Optional<UserChallenge> findById(Long id);

UserChallenge getByUserIdAndChallengeId(Long userId, Long challengeId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("해당 챌린지에 참여한 유저가 아닙니다.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<UserChallenge> findById(Long id) {
return userChallengeRepository.findById(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ public interface UserChallengeRepository extends JpaRepository<UserChallenge, Lo
"WHERE uc.id = :id")
Optional<UserChallenge> 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<UserChallenge> findByChallengeIdWithFetchLazy(@Param("challengeId") Long challengeId);
}

0 comments on commit 289dffd

Please sign in to comment.