Skip to content

Feat/week3#29

Open
zwo-n wants to merge 5 commits intoApptiveDev:강지원from
zwo-n:feat/week-3
Open

Feat/week3#29
zwo-n wants to merge 5 commits intoApptiveDev:강지원from
zwo-n:feat/week-3

Conversation

@zwo-n
Copy link
Copy Markdown

@zwo-n zwo-n commented Nov 14, 2025

변경점 👍

DTO 구현, 테스트 코드 수정 및 추가, member & like Entity 추가

테스트 💻

SpringBootTest를 활용한 테스트

비고 ✏

TDD 방식이 아직 미숙하여 테스트 코드 작성이 어렵게만 느껴집니다..

Copy link
Copy Markdown
Member

@Neibce Neibce left a comment

Choose a reason for hiding this comment

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

수고하셨습니다 다 잘 구현해주셨네요! 코멘트 몇 개 달아두었으니 확인해보시면 될 거 같습니다
제가 달아드린 내용들은 필수사항은 아니고, 단순 참고 정도로 보시면 될 거 같습니다..!

Comment on lines +27 to +28
this.likeCount = post.getLikes().size(); // 리스트 -> size()
this.commentCount = post.getComments().size();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

이 부분에서 N+1 문제가 발생할 거 같은데, N+1 문제와 해결방법들에 대해서 찾아보시면 좋을 거 같습니다!
물론 지금처럼 작은 규모의 프로젝트에서는 크게 문제없고 무시하고 진행하기도 합니다..!

  • 게시글 목록을 조회할 때마다 각 게시글의 likes, comments를 조회하는 추가 쿼리 발생
  • 100개의 게시글이면 201개의 SQL 쿼리 발생 (1 + 100 + 100)

Comment on lines +23 to +30
@OneToMany(mappedBy = "member")
private List<Post> posts = new ArrayList<>();

@OneToMany(mappedBy = "member")
private List<Comment> comments = new ArrayList<>();

@OneToMany(mappedBy = "member")
private List<Like> likes = new ArrayList<>();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Member 엔티티에 Post, Comment, Like가 꼭 필요한지에 대해서 고민해보시면 좋을 거 같습니다!

Comment on lines +24 to +27
Member member = memberRepository.findById(memberId)
.orElseThrow(() -> new RuntimeException("member not found"));
Post post = postRepository.findById(postId)
.orElseThrow(() -> new RuntimeException("post not found"));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

지금도 충분하지만, 커스텀 예외를 적용해서 예외에 대해 더 명확히 명시하는 것도 좋을 거 같습니다!

@JoinColumn(name = "post_id",nullable = false)
private Post post;

private LocalDateTime CreatedAt;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

모든 항목을 camelCase로 통일하는 것이 좋습니다!

Comment on lines +28 to +29
@OneToMany(mappedBy = "post", cascade = CascadeType.ALL,orphanRemoval = true)
private List<Comment> comments = new ArrayList<>();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

현재 Post->Comment, Comment->Post로 양방향 참조가 걸려있는 거 같은데, 보통은 단방향만으로도 충분한 경우가 대부분이니 한번 고민해보셔도 좋을 거 같습니다

import java.util.List;

@Service
public class CommentService {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

여기에도 Transactional 적용하면 좋을 거 같습니다

import java.util.Optional;

@RestController
@RequestMapping("/post")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

posts로 복수형으로 변경해서 통일시키는게 나을 거 같습니다!

private Member (String username, String email, String password){
this.username = username;
this.email = email;
this.password = password;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

지금은 비밀번호를 평문으로 DB에 저장하고 있지만, 실 서비스에서는 법적으로 단방향 암호화 후 저장이 필수이므로 암호화 후 비밀번호를 저장하는 방법도 공부해보시면 좋을 거 같습니다..!
image

Comment on lines +28 to +30
public List<Post> findAll(){
return postRepository.findAll();
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

페이지네이션을 적용해봐도 좋을 거 같습니다..!

Comment on lines +9 to +11
private String content;
private String username;
private Long memberId;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

DTO 내에 Validation을 적용해보는 것도 좋을 거 같습니다 음수나 빈 제목 등을 사전에 검증해 입력되는 걸 방지할 수 있습니다..!

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