-
Notifications
You must be signed in to change notification settings - Fork 0
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
chore: comment api 구현 #31
Conversation
kobaco/kobaco/build.gradle
Outdated
@@ -26,7 +26,7 @@ repositories { | |||
dependencies { | |||
implementation 'org.springframework.boot:spring-boot-starter-web' | |||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' | |||
// implementation 'org.springframework.boot:spring-boot-starter-security' | |||
implementation 'org.springframework.boot:spring-boot-starter-security' |
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.
비횔성화해주라
|
||
@PostMapping("/create") | ||
public ResponseEntity<CommentDTO> createComment(@RequestBody CommentDTO commentDTO, | ||
Authentication authentication) { |
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.
사용자 조회는 UserUtils의 메소드를 이용해서 조회해주라
|
||
@Service | ||
public class CommentService { | ||
private final CommentJpaRepository commentRepository; |
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.
JpaRepository를 직접 참조하기보다는 도메인 패키지에 Comment, CommentRepository를 만들고 참조해주라
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.
관련해서 내가 올려둔 pr을 보면서 같은 스타일로 만들어주라
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.
private final UserJpaRepository userRepository; | ||
|
||
@Autowired | ||
public CommentService(CommentJpaRepository commentRepository, UserJpaRepository userRepository) { |
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.
@RequiredArgsConstructor
를 사용해주라
.collect(Collectors.toList()); | ||
} | ||
|
||
private CommentDTO toDTO(CommentEntity 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.
dto로 변환할때는 setter를 사용하지 말고 생성자를 이용해서 만들어주라, 관련해서는 내가 올려둔 pr 확인해줘
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter |
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.
setter는 제거해주라
|
||
@Getter | ||
@Setter | ||
public class 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.
class 대신에 record를 찾아서 바꿔주라
@ElementCollection | ||
@CollectionTable(name = "comment_likes", joinColumns = @JoinColumn(name = "comment_id")) | ||
@Column(name = "user_email") | ||
private Set<String> likedBy = new HashSet<>(); |
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.
양방향 매핑은 사용하지말자, 댓글이 너무 많은 정보를 알게되고 성능 관련 최적화도 힘들어서
private final CommentLikeManager commentLikeManager; | ||
|
||
@Transactional | ||
public CommentDetail createComment(CommentDetail commentDetail, 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 받는 부분 final Long userId = userUtils.getRequestUserId();로 수정해주라
public class Comment { | ||
private Long commentId; | ||
private String content; | ||
private UserEntity commenter; |
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를 바로가지기보다는 Long userId를 가지는거 어때?
|
||
|
||
|
||
@Repository |
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.
JPA 인터페이스를 만들때는 @repository는 안넣어둬두 돼
} | ||
|
||
@Repository | ||
public static class CommentRepositoryImpl implements CommentRepository { |
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.
클래스 분리해주라
@Component | ||
@RequiredArgsConstructor | ||
public class CommentMapper { | ||
private final UserRepository userRepository; |
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.
mapper를 사용할때는 repository 의존성 없는게 좋을 것 같아
No description provided.