From 47b64c3835b3ff948be6ff78c2825b471471cbf5 Mon Sep 17 00:00:00 2001 From: mmihye Date: Fri, 7 Jun 2024 17:58:36 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[#48]=20fix:=20images=20null=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/place/service/PlaceService.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) 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..7cdde46 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 != null || images.isEmpty()){ + 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()); } From 75bcf88c85d00715537c4dc01b83a79ce7191574 Mon Sep 17 00:00:00 2001 From: mmihye Date: Fri, 7 Jun 2024 18:10:04 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[#48]=20fix:=20images=20null=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Together/domain/place/controller/PlaceController.java | 4 ++++ .../Journey/Together/domain/place/service/PlaceService.java | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) 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 7cdde46..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,7 +91,7 @@ public void createReview(Member member, List images, PlaceReviewR placeReviewRepository.save(placeReview); - if(images != null || images.isEmpty()){ + if(images.isEmpty() || images != null){ try { for(MultipartFile file : images) { String uuid = UUID.randomUUID().toString();