-
Notifications
You must be signed in to change notification settings - Fork 10
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
[8주차] cow mvc practice(BaekJaehyuk) #3
base: main
Are you sure you want to change the base?
Conversation
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.
이야 Postman 링크도 같이 올려주시면 좋을거 같아요! 아니면 swagger도 츄라이
src/main/java/com/cow/cow_mvc_practice/comment/controller/request/CreateCommentRequest.java
Outdated
Show resolved
Hide resolved
import lombok.Getter; | ||
|
||
@Getter | ||
public class CreateCommentResponse { |
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.
댓글을 생성하는 response? 라는 생각이 들어서 프론트에게 Comment 생성에 대한 정보를 넘겨줘야하는가? 라는 생각이 들게 됩니다! 만약 Comment 생성한 후 정보를 반환하고 싶은거라면 CommentResponse 또는CreatedCommnetReponse 와 같은 클래스 명을 사용할거 같아요! 반환의 이유가 있는지 확인해보고 결정해주세요!
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.
고민해 보겠습니다
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "comment_id") | ||
private Long id; |
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.
id를 Long type으로 설정한 이유가 있나요?
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.
경험상 uuid를 사용하는게 좋을 때도 많아서 한번쯤 알아두면 좋을거 같습니다
src/main/java/com/cow/cow_mvc_practice/comment/entity/Comment.java
Outdated
Show resolved
Hide resolved
|
||
@RequiredArgsConstructor | ||
@Service | ||
@Transactional |
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.
Transactional을 interface에도 달고 구현체에도 달게 되면 어떻게 될까요?
src/main/java/com/cow/cow_mvc_practice/comment/service/CommentServiceImpl.java
Outdated
Show resolved
Hide resolved
src/main/java/com/cow/cow_mvc_practice/member/repository/MemberRepositoryImpl.java
Outdated
Show resolved
Hide resolved
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.
커밋도 더 디테일하게 나눠 주시면 좋을 것 같아요 고생하셨습니다
Long postId; | ||
String content; | ||
|
||
public Comment toEntity() { |
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.
사용 안하시고 계신데 toEntity를 만들어 놓은 이유가 있을까요
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.
@Hoya324 호야씨가 만들어 놓으셨어요
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.
사용하셔야죠
src/main/java/com/cow/cow_mvc_practice/comment/controller/response/CreateCommentResponse.java
Outdated
Show resolved
Hide resolved
src/main/java/com/cow/cow_mvc_practice/comment/controller/CommentController.java
Outdated
Show resolved
Hide resolved
src/main/java/com/cow/cow_mvc_practice/comment/entity/Comment.java
Outdated
Show resolved
Hide resolved
src/main/java/com/cow/cow_mvc_practice/comment/service/CommentServiceImpl.java
Outdated
Show resolved
Hide resolved
Member member = findMemberById(createCommentRequest.getMemberId()); | ||
Post post = findPostById(createCommentRequest.getPostId()); | ||
|
||
Comment comment = Comment.of(createCommentRequest.getContent(), post, member); |
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 객체를 만들때 연관관계 주입을 해주지 않고, 따로 편의 메소드로 작성하는 것이 좋을 것 같습니다.(post,member)
Member member = findMemberById(createCommentRequest.getMemberId()); | ||
Post post = findPostById(createCommentRequest.getPostId()); | ||
|
||
Comment comment = Comment.of(createCommentRequest.getContent(), post, member); |
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.
CraeteCommentRequest의 toEntity메소드를 사용하여 인스턴스 생성하는 것이 더 좋아보입니다.
|
||
Comment comment = Comment.of(createCommentRequest.getContent(), post, member); | ||
commentRepository.save(comment); | ||
post.addComment(comment); |
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.
연관관계 편의 메소드를 만들어 한번에 관리해주세요
|
||
// 게시글 삭제 | ||
@DeleteMapping("/{postId}") | ||
public ResponseEntity<Long> deletePost(@PathVariable Long 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.
다른 부분은 ResponseEntity를 적용하지 않으셨는데, 따로 이 부분만 적용하신 이유가 있을까요?
추가 Q & A
🤔 잘 모르겠거나, 더 궁금한 내용이 있었나요?
집중적으로 리뷰 받고싶은 것이 있나요?