Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat/#48] 이미지없는경우 null 처리 #49

Merged
merged 2 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
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 @@ -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