Conversation
|
|
||
| private String content; | ||
|
|
||
| private String writer; |
There was a problem hiding this comment.
User엔티티와 연관관계 매핑 안하고 writer를 사용한 이유가 궁금합니다..!
|
|
||
| // 글 작성 | ||
| @Transactional | ||
| public PostDto createPost(PostDto postDto, Long userId) { |
There was a problem hiding this comment.
회원가입 부분 빼고 먼저 풀었어서 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.
userDto.getNickname() == null || userDto.getNickname().isEmpty()
=> userDto.getNickname().isBlank() 로 줄일 수 있을듯?
There was a problem hiding this comment.
is.Empty(), isBlank() 차이 공부해봐도 좋겠죵??
| private String writer; | ||
|
|
||
| private int commentCount; | ||
| } |
There was a problem hiding this comment.
createdAt를 넣지 않은 이유가 모야?
postId를 넣은 이유는 모야?
There was a problem hiding this comment.
createdAt을 클라이언트에 보낼 필요 없다구 생각했고
postId는 나중에 삭제나 업데이트 같은 기능 추가할 때 식별하기 위해 넣었슴다
|
|
||
| private String content; | ||
|
|
||
| private String writer; |
There was a problem hiding this comment.
Post랑 User도 ManyToOne 연관관계가 있다고 생각하는데
매핑 안 한 이유가 모야?
| @Column(nullable = false, unique = true) | ||
| private String nickname; | ||
|
|
||
| } No newline at end of file |
| throw new RuntimeException("아이디가 이미 존재합니다."); | ||
| } | ||
| if (userRepository.existsByNickname(userDto.getNickname())) { | ||
| throw new RuntimeException("닉네임이 이미 존재합니다."); |
There was a problem hiding this comment.
예외처리 할 거면 RuntimeException보다 지훈님이 알려주신 NoSuchElement 쓰는 게 나을듯??
There was a problem hiding this comment.
RuntimeException, NoSuchElement, ResponseStatusException 다 좋아용~
추후에 커스텀 예외처리하는법 알려줄게요~
| post.setWriter(postDto.getWriter()); | ||
| post.setCommentCount(0); | ||
| post.setCreatedAt(LocalDateTime.now()); | ||
| postRepository.save(post); |
There was a problem hiding this comment.
근데 updatedAt 썼던데 여기서 초기화해야 할 것 가타
| commentRepository.save(comment); | ||
| commentDto.setPostId(post.getId()); | ||
| return commentDto; | ||
| } |
There was a problem hiding this comment.
혹시 댓글 작성해서 댓글 수 올라가는 로직 어디에 작성했어?
| comment.setWriter(commentDto.getWriter()); | ||
| comment.setPost(post); | ||
| commentRepository.save(comment); | ||
| commentDto.setPostId(post.getId()); |
There was a problem hiding this comment.
postId도 CommentDto에 있으니까 입력할 때 받는거 아닌가여 setPostId를 하는 이유가 궁금합니다

No description provided.