diff --git a/src/main/java/com/example/stepperbackend/converter/PostConverter.java b/src/main/java/com/example/stepperbackend/converter/PostConverter.java index 5c4cd75..2d6ea79 100644 --- a/src/main/java/com/example/stepperbackend/converter/PostConverter.java +++ b/src/main/java/com/example/stepperbackend/converter/PostConverter.java @@ -26,10 +26,7 @@ public static Post toEntity(PostDto.PostRequestDto dto, Member member, WeeklyMis .build(); } - public static PostDto.PostResponseDto toDto(Post post, List imageList) { - List imageDtoList = imageList.stream() - .map(ImageConverter::toDto).collect(Collectors.toList()); - + public static PostDto.PostResponseDto toDto(Post post) { return PostDto.PostResponseDto.builder() .id(post.getId()) //.imageUrl(post.getImageUrl()) @@ -41,7 +38,6 @@ public static PostDto.PostResponseDto toDto(Post post, List imageList) { .weeklyMissionTitle(post.getWeeklyMission() != null ? post.getWeeklyMission().getMissionTitle() : null) .createdAt(post.getCreatedAt()) .updatedAt(post.getUpdatedAt()) - .imageList(imageDtoList) .build(); } diff --git a/src/main/java/com/example/stepperbackend/service/PostService/PostServiceImpl.java b/src/main/java/com/example/stepperbackend/service/PostService/PostServiceImpl.java index a5aafb5..43a5775 100644 --- a/src/main/java/com/example/stepperbackend/service/PostService/PostServiceImpl.java +++ b/src/main/java/com/example/stepperbackend/service/PostService/PostServiceImpl.java @@ -52,20 +52,23 @@ public PostDto.PostResponseDto createPost(List images, PostDto.Po postRepository.save(post); //이미지 저장 - List imageList = imageUrlList.stream() - .map(imageUrl -> { - Image image = ImageConverter.toEntity(imageUrl, post); - return imageRepository.save(image); - }) - .collect(Collectors.toList()); - post.setImageList(imageList); + List imageList = null; + if (imageUrlList != null) { + imageList = imageUrlList.stream() + .map(imageUrl -> { + Image image = ImageConverter.toEntity(imageUrl, post); + return imageRepository.save(image); + }) + .collect(Collectors.toList()); + post.setImageList(imageList); + } // 첫 커뮤니티 게시글 작성 완료 if (postRepository.getCountByMember(member) == 1) { badgeService.putFirstBadge("첫 게시글 작성 완료", member); } - return PostConverter.toDto(post, imageList); + return PostConverter.toDto(post); } @Override