Skip to content

Conversation

@nayoung04
Copy link

No description provided.

Copy link

@SANGHEEJEONG SANGHEEJEONG left a comment

Choose a reason for hiding this comment

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

우왕 전체적으로 내 코드랑 비슷한 것 같아

private String content;

private int commentCount;

Choose a reason for hiding this comment

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

createdAt은 Dto에 왜 안 넣었어?

Copy link
Author

Choose a reason for hiding this comment

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

Dto에 넣으니까 파라미터로 입력을 받지 않아서 null로 반환하길래 빼긴 했는데
엔티티에서 Dto로 변환할때 setPostedAt을 하는 방법도 있었군,,

Copy link
Member

Choose a reason for hiding this comment

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

아주 좋아용~~ 이거에 대해서는 오늘 알려줄게용~~


List<Post> findAllByOrderByPostedAtDesc();

List<Post> findAllByUserId(Long userId);

Choose a reason for hiding this comment

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

오 나는 Jpa가 이렇게 똑똑한 줄 몰랐네

JPA에서는 경로를 명확히 지정하는 게 안전하지만, 지금처럼 연관 관계가 명확하게 설정되어 있다면 findAllByUsername처럼 짧은 메서드명으로도 작동할 수 있다. 하지만 현재 돌아가고 있으면 괜찮지만, 다른 팀원이나 미래의 개발자가 코드를 이해하기 쉽게 명시적으로 작성하는 것이 권장된다.

나는 findAllByUse_Username으로 쿼리 날리려고 메서드명 작성했는데 찾아보니까 연관 관계가 매핑되어 있으면 줄여써도 가능하구낭


@RestController
@RequiredArgsConstructor
@RequestMapping("/posts")

Choose a reason for hiding this comment

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

@RequestMapping("/posts/comments")

이렇게 써도 될 듯
(댓글을 한 개라도 더 달려는 노력..)

Copy link
Author

Choose a reason for hiding this comment

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

아하 엔드포인트 그냥 받아적다 보니 똑같다는걸 인지를 못했네..

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.

4 participants