Skip to content

Commit

Permalink
Merge pull request #49 from Journey-Together/feat/#48
Browse files Browse the repository at this point in the history
[Feat/#48] 이미지없는경우 null 처리
  • Loading branch information
mmihye authored Jun 7, 2024
2 parents 7be61d2 + 75bcf88 commit 0130fec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -41,6 +42,9 @@ public ApiResponse<?> createReivew(@AuthenticationPrincipal PrincipalDetails pri
@RequestPart(required = false) List<MultipartFile> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,17 @@ public void createReview(Member member, List<MultipartFile> 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());
}


Expand Down

0 comments on commit 0130fec

Please sign in to comment.