diff --git a/src/main/java/Journey/Together/domain/place/controller/PlaceController.java b/src/main/java/Journey/Together/domain/place/controller/PlaceController.java index 11e90db..aea9492 100644 --- a/src/main/java/Journey/Together/domain/place/controller/PlaceController.java +++ b/src/main/java/Journey/Together/domain/place/controller/PlaceController.java @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import java.util.ArrayList; import java.util.List; @RestController @@ -41,6 +42,9 @@ public ApiResponse createReivew(@AuthenticationPrincipal PrincipalDetails pri @RequestPart(required = false) List images, @RequestPart("placeReviewReq") PlaceReviewReq placeReviewReq, @PathVariable Long placeId) { + if (images == null) { + images = new ArrayList<>(); // images가 null이면 빈 리스트로 초기화 + } placeService.createReview(principalDetails.getMember(), images,placeReviewReq, placeId); return ApiResponse.success(Success.CREATE_PLACE_REVIEW_SUCCESS); } diff --git a/src/main/java/Journey/Together/domain/place/service/PlaceService.java b/src/main/java/Journey/Together/domain/place/service/PlaceService.java index d7bf6de..1b63e93 100644 --- a/src/main/java/Journey/Together/domain/place/service/PlaceService.java +++ b/src/main/java/Journey/Together/domain/place/service/PlaceService.java @@ -91,15 +91,17 @@ public void createReview(Member member, List images, PlaceReviewR placeReviewRepository.save(placeReview); - try { - for(MultipartFile file : images) { - String uuid = UUID.randomUUID().toString(); - final String imageUrl = s3Client.upload(file, POST_IMAGE_FOLDER_NAME+member.getMemberId(), uuid); - PlaceReviewImg placeReviewImg = PlaceReviewImg.builder().placeReview(placeReview).imgUrl(imageUrl).build(); - placeReviewImgRepository.save(placeReviewImg); + if(images.isEmpty() || images != null){ + try { + for(MultipartFile file : images) { + String uuid = UUID.randomUUID().toString(); + final String imageUrl = s3Client.upload(file, POST_IMAGE_FOLDER_NAME+member.getMemberId(), uuid); + PlaceReviewImg placeReviewImg = PlaceReviewImg.builder().placeReview(placeReview).imgUrl(imageUrl).build(); + placeReviewImgRepository.save(placeReviewImg); + } + } catch (RuntimeException e) { + throw new RuntimeException(e.getMessage()); } - } catch (RuntimeException e) { - throw new RuntimeException(e.getMessage()); }