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

[FEAT] 홈 화면 즐겨찾기 API 구현 #75

Merged
merged 8 commits into from
Mar 13, 2024

Conversation

eeddiinn
Copy link
Contributor

@eeddiinn eeddiinn commented Mar 10, 2024

📌 관련 이슈

closed #74

✨ 어떤 이유로 변경된 내용인지

  • 즐겨찾기 기능을 위한 API를 구현했습니다.
  • 즐겨찾는 레큐북 등록하기 API는 레큐북 Id와 엑세스 토큰을 받아 즐겨찾기를 등록할 수 있도록 하였습니다.
  • 즐겨찾는 레큐북 조회하기 API는 엑세스 토큰을 받아 그 멤버가 즐겨찾기 해놓은 레큐북 목록들을 가져올 수 있도록 하였습니다.
  • 구현을 위해 새로운 엔티티 Favorite을 만들었습니다.

🙏 검토 혹은 리뷰어에게 남기고 싶은 말

  • 동섭빠 도와줘서 감사용가링 ! ! 🤩
  • 글고 즐겨찾기는 갯수 제한 없나여 ?-?
  • tab size 4로 했는데 먼가 안된거 같아서 확인 함 해주세욤

@eeddiinn eeddiinn self-assigned this Mar 10, 2024
@eeddiinn eeddiinn added 🪄API 서버 API 통신 ✨Feat 새로운 기능 추가 예진❄️ 🔥 Pull Request PR 날림 labels Mar 10, 2024
Copy link
Contributor

@dong2ast dong2ast left a comment

Choose a reason for hiding this comment

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

고생 많으셨습니다~~ 다른 api처럼 컨트롤러에 interface 단도 추가해주세요~! 👍 👍

Comment on lines 35 to 36
book.addFavorite(favorite);
member.addFavorite(favorite);
Copy link
Contributor

Choose a reason for hiding this comment

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

[P2] 이런 연관관계 매핑 로직은 일대다 : 다대일 관계를 풀어주는 중간다리 객체를 생성할 때 함께 넣어주는게 추후 실수할 가능성도 줄이고 코드를 깔끔히 하는데도 더 좋습니다!
방법은 아래 예시를 들어드릴게요~

Comment on lines 33 to 35
public static Favorite of(Member member, Book book) {
return new Favorite(member, book);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public static Favorite of(Member member, Book book) {
return new Favorite(member, book);
}
public static Favorite of(Member member, Book book) {
Favorite favorite = new Favorite(member, book);
book.addFavorite(favorite);
member.addFavorite(favorite);
return favorite;
}

위에서 얘기한 수정 사항입니다~ 이거를 아마 '연관관계 편의성 설정' 뭐 이렇게 불렀던 것 같은데 혹시 더 궁금하면 한번 찾아보세요 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

오호 새롭게 알고갑니당 !!!!!

@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)

[P1] ManyToOne 관계에서는 기본적으로 지연로딩을 설정하는 것이 좋습니다. 안그러면 N+1 문제가 발생할 수 있어요!
이부분은 구글에 검색해보면 자세히 나올건데 간단히 설명드리면

  1. ManyToOne 관계는 기본적으로 EAGER 즉, 즉시로딩이 기본 설정입니다.
  2. 따라서 OneToMany 관계에 있는 데이터를 조회할 때 (예를 들면 Member), Member와 연결되어 있는 Favorite 객체도 같이 조회하려고 합니다.
  3. 근데 Member 1개에는 여러개의 Favorite이 존재하죠?? 그러면 그 Favorite만큼 DB에 쿼리를 날려서 Favorite 데이터를 가져오게 됩니다.
  4. 단지 Member를 1을 조회하려고 한 것 뿐인데 N번의 쿼리가 날라갔죠?? 이게 N+1 문제입니다.

그래서 지연로딩을 걸면 Member를 조회할 때 Favorite의 프록시 객체(이것도 궁금하면 찾아보세영 ㅋㅋ)가 주입되게 되고, 실제 Favorite을 조회하지 않는 이상 추가적인 쿼리가 발생하지 않게 됩니다!

이것도 따봉만 날리고 가봐라 현예진

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ㅋㅋㅋㅋㅋㅋㅋㅋㅋ 왕 자세한 설명 감쟈합니다 ...!!!!!! 바로 반영할게유


@RestController
@RequiredArgsConstructor
@RequestMapping("api/favorite")
Copy link
Contributor

Choose a reason for hiding this comment

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

앞에 / 없는거 뭔가... 뭔가.. 불편한데.................

Copy link
Contributor Author

Choose a reason for hiding this comment

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

아차차 실수 ......................🤣

Copy link
Member

@ddongseop ddongseop left a comment

Choose a reason for hiding this comment

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

수고하셨습니다! 동휘가 리뷰 남겨준 부분 다 반영만 한다면 충분할 것 같아요!
추가로, 즐겨찾기 개수 제한 관련해서 논의 후에 알려드리겠습니다!

@eeddiinn eeddiinn merged commit 61d9b94 into develop Mar 13, 2024
1 check passed
@eeddiinn eeddiinn deleted the feat/#74-home_favorites_api branch March 13, 2024 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
예진❄️ 🪄API 서버 API 통신 ✨Feat 새로운 기능 추가 🔥 Pull Request PR 날림
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEAT] 홈 화면 즐겨찾기 API 구현
3 participants