-
Notifications
You must be signed in to change notification settings - Fork 2
3-2 #3
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
base: hyerim
Are you sure you want to change the base?
3-2 #3
Conversation
|
|
||
| private String content; | ||
|
|
||
| private String writer; |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
파라미터로 받은 userId는 어디서 사용하는 건가요?
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
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() 로 줄일 수 있을듯?
There was a problem hiding this comment.
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; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createdAt를 넣지 않은 이유가 모야?
postId를 넣은 이유는 모야?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Post랑 User도 ManyToOne 연관관계가 있다고 생각하는데
매핑 안 한 이유가 모야?
There was a problem hiding this comment.
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; | ||
|
|
||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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("닉네임이 이미 존재합니다."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
예외처리 할 거면 RuntimeException보다 지훈님이 알려주신 NoSuchElement 쓰는 게 나을듯??
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
근데 updatedAt 썼던데 여기서 초기화해야 할 것 가타
There was a problem hiding this comment.
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; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
혹시 댓글 작성해서 댓글 수 올라가는 로직 어디에 작성했어?
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
postId도 CommentDto에 있으니까 입력할 때 받는거 아닌가여 setPostId를 하는 이유가 궁금합니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
맞는 말씀입니다

No description provided.