diff --git a/src/main/java/com/likelion13/artium/domain/exhibition/service/ExhibitionServiceImpl.java b/src/main/java/com/likelion13/artium/domain/exhibition/service/ExhibitionServiceImpl.java index a088370..c8f527a 100644 --- a/src/main/java/com/likelion13/artium/domain/exhibition/service/ExhibitionServiceImpl.java +++ b/src/main/java/com/likelion13/artium/domain/exhibition/service/ExhibitionServiceImpl.java @@ -100,10 +100,6 @@ public ExhibitionDetailResponse createExhibition(MultipartFile image, Exhibition } List pieces = buildPieces(request.getPieceIdList()); - List exhibitionParticipantList = - buildParticipants(request.getParticipantIdList()); - - exhibitionParticipantRepository.saveAll(exhibitionParticipantList); User currentUser = userService.getCurrentUser(); @@ -114,6 +110,10 @@ public ExhibitionDetailResponse createExhibition(MultipartFile image, Exhibition try { exhibitionRepository.save(exhibition); + List exhibitionParticipantList = + buildParticipants(request.getParticipantIdList(), exhibition); + + exhibitionParticipantRepository.saveAll(exhibitionParticipantList); } catch (Exception e) { if (imageUrl != null) { s3Service.deleteFile(s3Service.extractKeyNameFromUrl(imageUrl)); @@ -472,7 +472,8 @@ public ExhibitionDetailResponse updateExhibition( } List pieces = buildPieces(distinctPieceIds); - List participants = buildParticipants(request.getParticipantIdList()); + List participants = + buildParticipants(request.getParticipantIdList(), exhibition); exhibitionParticipantRepository.deleteAll(exhibition.getExhibitionParticipants()); exhibition.getExhibitionParticipants().clear(); @@ -668,7 +669,7 @@ private ExhibitionStatus determineStatus(LocalDate startDate, LocalDate endDate) } } - private List buildParticipants(List userIds) { + private List buildParticipants(List userIds, Exhibition exhibition) { return userIds.stream() .distinct() .map( @@ -677,7 +678,10 @@ private List buildParticipants(List userIds) { userRepository .findById(userId) .orElseThrow(() -> new CustomException(UserErrorCode.USER_NOT_FOUND)); - return ExhibitionParticipant.builder().exhibition(null).user(participantUser).build(); + return ExhibitionParticipant.builder() + .exhibition(exhibition) + .user(participantUser) + .build(); }) .collect(Collectors.toList()); }