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

[FIX] 커뮤니티 게시글 작성 API 이미지 null값 허용 #158

Merged
merged 1 commit into from
Aug 20, 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 @@ -26,10 +26,7 @@ public static Post toEntity(PostDto.PostRequestDto dto, Member member, WeeklyMis
.build();
}

public static PostDto.PostResponseDto toDto(Post post, List<Image> imageList) {
List<ImageDto.ImageResponseDto> 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())
Expand All @@ -41,7 +38,6 @@ public static PostDto.PostResponseDto toDto(Post post, List<Image> imageList) {
.weeklyMissionTitle(post.getWeeklyMission() != null ? post.getWeeklyMission().getMissionTitle() : null)
.createdAt(post.getCreatedAt())
.updatedAt(post.getUpdatedAt())
.imageList(imageDtoList)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,23 @@ public PostDto.PostResponseDto createPost(List<MultipartFile> images, PostDto.Po
postRepository.save(post);

//이미지 저장
List<Image> imageList = imageUrlList.stream()
.map(imageUrl -> {
Image image = ImageConverter.toEntity(imageUrl, post);
return imageRepository.save(image);
})
.collect(Collectors.toList());
post.setImageList(imageList);
List<Image> 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
Expand Down
Loading