Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ public ExhibitionDetailResponse createExhibition(MultipartFile image, Exhibition
}

List<ExhibitionPiece> pieces = buildPieces(request.getPieceIdList());
List<ExhibitionParticipant> exhibitionParticipantList =
buildParticipants(request.getParticipantIdList());

exhibitionParticipantRepository.saveAll(exhibitionParticipantList);

User currentUser = userService.getCurrentUser();

Expand All @@ -114,6 +110,10 @@ public ExhibitionDetailResponse createExhibition(MultipartFile image, Exhibition

try {
exhibitionRepository.save(exhibition);
List<ExhibitionParticipant> exhibitionParticipantList =
buildParticipants(request.getParticipantIdList(), exhibition);

exhibitionParticipantRepository.saveAll(exhibitionParticipantList);
} catch (Exception e) {
if (imageUrl != null) {
s3Service.deleteFile(s3Service.extractKeyNameFromUrl(imageUrl));
Expand Down Expand Up @@ -472,7 +472,8 @@ public ExhibitionDetailResponse updateExhibition(
}

List<ExhibitionPiece> pieces = buildPieces(distinctPieceIds);
List<ExhibitionParticipant> participants = buildParticipants(request.getParticipantIdList());
List<ExhibitionParticipant> participants =
buildParticipants(request.getParticipantIdList(), exhibition);

exhibitionParticipantRepository.deleteAll(exhibition.getExhibitionParticipants());
exhibition.getExhibitionParticipants().clear();
Expand Down Expand Up @@ -668,7 +669,7 @@ private ExhibitionStatus determineStatus(LocalDate startDate, LocalDate endDate)
}
}

private List<ExhibitionParticipant> buildParticipants(List<Long> userIds) {
private List<ExhibitionParticipant> buildParticipants(List<Long> userIds, Exhibition exhibition) {
return userIds.stream()
.distinct()
.map(
Expand All @@ -677,7 +678,10 @@ private List<ExhibitionParticipant> buildParticipants(List<Long> 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());
}
Expand Down