Skip to content
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

Merged
merged 6 commits into from
Mar 4, 2024
Merged

chore: comment api 구현 #31

merged 6 commits into from
Mar 4, 2024

Conversation

jihyo-j
Copy link
Member

@jihyo-j jihyo-j commented Mar 1, 2024

No description provided.

@@ -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'
Copy link
Member

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) {
Copy link
Member

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;
Copy link
Member

Choose a reason for hiding this comment

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

JpaRepository를 직접 참조하기보다는 도메인 패키지에 Comment, CommentRepository를 만들고 참조해주라

Copy link
Member

Choose a reason for hiding this comment

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

관련해서 내가 올려둔 pr을 보면서 같은 스타일로 만들어주라

Copy link
Member

Choose a reason for hiding this comment

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

#32

private final UserJpaRepository userRepository;

@Autowired
public CommentService(CommentJpaRepository commentRepository, UserJpaRepository userRepository) {
Copy link
Member

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) {
Copy link
Member

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
Copy link
Member

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 {
Copy link
Member

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<>();
Copy link
Member

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) {
Copy link
Member

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;
Copy link
Member

Choose a reason for hiding this comment

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

User를 바로가지기보다는 Long userId를 가지는거 어때?




@Repository
Copy link
Member

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 {
Copy link
Member

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;
Copy link
Member

Choose a reason for hiding this comment

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

mapper를 사용할때는 repository 의존성 없는게 좋을 것 같아

@jihyo-j jihyo-j merged commit 11c5743 into main Mar 4, 2024
1 check passed
@jihyo-j jihyo-j deleted the chore/Comment branch March 4, 2024 11:14
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.

2 participants