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

[#91] Series 기능 NPE 문제 해결 #89

Merged
merged 1 commit into from
Jan 27, 2023
Merged
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 @@ -46,6 +46,7 @@ public class PostServiceImpl implements PostService {
private final PostTagRepository postTagRepository;
private final UserTagRepository userTagRepository;


@Override
@Transactional
public Long save(CreateRequest request, Long userId) {
Expand All @@ -60,15 +61,16 @@ public Long save(CreateRequest request, Long userId) {
private void registerSeries(CreateRequest request, Post post, User owner) {
String seriesTitle = request.seriesTitle();
if (seriesTitle == null || seriesTitle.isBlank()) {
return;
seriesTitle = "시리즈 없음";
}
final String finalSeriesTitle = seriesTitle;
Series series = seriesRepository
.findByIdAndTitle(owner.getId(), seriesTitle)
.orElseGet(() -> seriesRepository.save(
Series.builder()
.title(seriesTitle)
.user(owner)
.build()
Series.builder()
.title(finalSeriesTitle)
.user(owner)
.build()
)
);
post.setSeries(series);
Expand All @@ -77,7 +79,7 @@ private void registerSeries(CreateRequest request, Post post, User owner) {
@Override
public PostResponse findById(Long postId) {
Post post = postRepository.joinCommentFindById(postId)
.orElseThrow(() -> new IllegalArgumentException("exception.post.notExists"));
.orElseThrow(() -> new IllegalArgumentException(POST_NOT_EXIST_MESSAGE));
Set<PostTag> findPostTags = postTagRepository.joinRootTagFindByPostId(postId);
post.addPostTagsFrom(findPostTags);
return PostResponse.toPostResponse(post);
Expand All @@ -93,7 +95,7 @@ public Page<PostResponse> findAll(Pageable pageable) {
@Transactional
public PostResponse update(UpdateRequest update, Long userId, Long postId) {
Post findPost = postRepository.joinUserFindById(postId)
.orElseThrow(() -> new IllegalArgumentException("exception.post.notExists"));
.orElseThrow(() -> new IllegalArgumentException(POST_NOT_EXIST_MESSAGE));

if (!findPost.getUser().checkSameUserId(userId)) {
throw new IllegalArgumentException("exception.post.not.owner");
Expand Down