Skip to content

Conversation

@HyerimH
Copy link

@HyerimH HyerimH commented Oct 28, 2024

No description provided.


private String content;

private String writer;
Copy link

@nayoung04 nayoung04 Oct 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

User엔티티와 연관관계 매핑 안하고 writer를 사용한 이유가 궁금합니다..!


// 글 작성
@Transactional
public PostDto createPost(PostDto postDto, Long userId) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

파라미터로 받은 userId는 어디서 사용하는 건가요?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

회원가입 부분 빼고 먼저 풀었어서 userId를 통해 글작성을 했었어여 수정하는중..!

if (userDto.getPassword() == null || userDto.getPassword().isEmpty()) {
throw new RuntimeException("비밀번호를 입력해 주세요.");
}
if (userDto.getNickname() == null || userDto.getNickname().isEmpty()) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

userDto.getNickname() == null || userDto.getNickname().isEmpty()
=> userDto.getNickname().isBlank() 로 줄일 수 있을듯?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is.Empty(), isBlank() 차이 공부해봐도 좋겠죵??

private String writer;

private int commentCount;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createdAt를 넣지 않은 이유가 모야?
postId를 넣은 이유는 모야?

Copy link
Author

@HyerimH HyerimH Oct 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createdAt을 클라이언트에 보낼 필요 없다구 생각했고
postId는 나중에 삭제나 업데이트 같은 기능 추가할 때 식별하기 위해 넣었슴다


private String content;

private String writer;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PostUserManyToOne 연관관계가 있다고 생각하는데
매핑 안 한 이유가 모야?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

추가했어요

@Column(nullable = false, unique = true)
private String nickname;

}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EndOfFile 설정하면
image
이거 안 뜨게 할 수 있음

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw new RuntimeException("아이디가 이미 존재합니다.");
}
if (userRepository.existsByNickname(userDto.getNickname())) {
throw new RuntimeException("닉네임이 이미 존재합니다.");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

예외처리 할 거면 RuntimeException보다 지훈님이 알려주신 NoSuchElement 쓰는 게 나을듯??

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RuntimeException, NoSuchElement, ResponseStatusException 다 좋아용~
추후에 커스텀 예외처리하는법 알려줄게요~

post.setWriter(postDto.getWriter());
post.setCommentCount(0);
post.setCreatedAt(LocalDateTime.now());
postRepository.save(post);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

근데 updatedAt 썼던데 여기서 초기화해야 할 것 가타

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commentRepository.save(comment);
commentDto.setPostId(post.getId());
return commentDto;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

혹시 댓글 작성해서 댓글 수 올라가는 로직 어디에 작성했어?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

추가했습니다 하하ㅏ

comment.setWriter(commentDto.getWriter());
comment.setPost(post);
commentRepository.save(comment);
commentDto.setPostId(post.getId());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

postId도 CommentDto에 있으니까 입력할 때 받는거 아닌가여 setPostId를 하는 이유가 궁금합니다

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

맞는 말씀입니다

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants