From 6f6d37fc235b87b53b6c762ecf864fb9cd2746dc Mon Sep 17 00:00:00 2001 From: hyojin425 Date: Tue, 20 Aug 2024 19:14:50 +0900 Subject: [PATCH] =?UTF-8?q?[FIX]=20=EC=BB=A4=EB=AE=A4=EB=8B=88=ED=8B=B0=20?= =?UTF-8?q?=EA=B2=8C=EC=8B=9C=EA=B8=80=20=EC=9E=91=EC=84=B1=20API=20?= =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A7=80=20null=EA=B0=92=20=ED=97=88?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../converter/PostConverter.java | 6 +----- .../service/PostService/PostServiceImpl.java | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 13 deletions(-) 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