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

[BE] feat: 섹션 이름 조회 API 구현 #801

Merged
merged 5 commits into from
Oct 11, 2024

Conversation

Kimprodp
Copy link
Contributor

@Kimprodp Kimprodp commented Oct 9, 2024


🚀 어떤 기능을 구현했나요 ?

  • 섹션 조회 이름 목록을 응답하는 API를 구현했습니다.

🔥 어떻게 해결했나요 ?

  • /v2/sections 에 대한 응답으로 리뷰 답변과 상관 없이 모든 섹션 이름을 응답합니다.

📝 어떤 부분에 집중해서 리뷰해야 할까요?

📚 참고 자료, 할 말

@Kimprodp Kimprodp added the ✨ BE label Oct 9, 2024
@Kimprodp Kimprodp added this to the 6차 스프린트: 최종장 milestone Oct 9, 2024
@Kimprodp Kimprodp self-assigned this Oct 9, 2024
@Kimprodp Kimprodp linked an issue Oct 9, 2024 that may be closed by this pull request
@donghoony donghoony changed the title [BE] feat: 섹셕 이름 조회 API 구현 [BE] feat: 섹션 이름 조회 API 구현 Oct 9, 2024
Copy link

github-actions bot commented Oct 9, 2024

Test Results

117 tests  +2   117 ✅ +2   4s ⏱️ -1s
 45 suites +1     0 💤 ±0 
 45 files   +1     0 ❌ ±0 

Results for commit be6424b. ± Comparison against base commit 65bdfb3.

♻️ This comment has been updated with latest results.

Copy link
Contributor

@donghoony donghoony left a comment

Choose a reason for hiding this comment

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

제안 사항과 함께 어프룹합니다! 고생했어요요~

@@ -34,7 +33,7 @@ public class Section {
@Enumerated(EnumType.STRING)
private VisibleType visibleType;

@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
Copy link
Contributor

Choose a reason for hiding this comment

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

기본값이 LAZY지만, 그래도 이를 명시하면 좋겠습니다 ㅎㅎ

Copy link
Contributor Author

Choose a reason for hiding this comment

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

이 부분은 다시 EAGER로 변경할게요, 테스트 깨지는 부분이 LazyInitializationException 이라서 테스트에 @transactional을 사용하지 않을 거라면 서비스단에서 fetch join 해줘야 할 것 같은데요, 이미 다른 이슈에서 다루고 있으니 한번에 적용해도 좋을 것 같아요.

Comment on lines +26 to +29
List<SectionNameResponse> sectionNameResponses = sectionRepository.findAllByTemplateId(reviewGroup.getTemplateId())
.stream()
.map(section -> new SectionNameResponse(section.getId(), section.getSectionName()))
.toList();
Copy link
Contributor

Choose a reason for hiding this comment

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

(다같이 생각 나누면 좋겠습니다)
현재 이 로직은 섹션의 ID, 이름만을 필요로 해요. 하지만 Repository에서는 Section을 반환하기 때문에 불필요한 Column까지 조회하고 있네요 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

템플릿 내 섹션이 많지 않아서 괜찮을 것 같다는 생각입니다. (사용자가 작성해야 하는 리뷰 항목이랑 직결되니 아주 많아 지지 않을 것 같아요)
다만, 후에 조회를 분리하여 조회용 dto를 도입한다고 하면 어차피 조회용 dto를 만들어야 하니 그때는 id와 name만을 가지는 dto를 만들어서 사용해도 괜찮을 것 같습니다~

Copy link
Contributor

Choose a reason for hiding this comment

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

엔티티의 하나의 속성만 필요하다면 해당 속성만 가져오는 게 되겠지만, 그렇지 않은 경우는 1. db-service dto를 만들거나 2. 일단 엔티티째로 가져와서 꺼내쓰기 이 두가지 방법이 떠올라요.

1번으로 하면 불필요한 속성을 안가져올 수 있지만 별도의 dto를 만들어야한다는 단점이 있고,
2번은 불필요한 연관관계 쿼리가 나가거나, 필요하지 않은 데이터까지 메모리에 불러와진다는 단점이 있겠네요.
하지만 2번의 단점 2가지 모두 캐시를 적용하면 상관없어진다고 생각해서 section 엔티티 통째로 받아오는 것이 간단해보입니다!

비교할만한 다른 방법이 또 있을까요?

Copy link
Contributor

Choose a reason for hiding this comment

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

쿼리 전용 Dto 를 사용하면 효율적일 부분들이 분명히 존재합니다.
예를 들어서 여러 엔티티에 대한 정보를 조회해와야 하는 경우
혹은 FetchType 이 Eager 로 되어있는 다른 컬럼들을 로드하는 것을 막을 수 있는 경우
하지만 이런 코드가 많아진다면, 레포지토리 함수 재사용률이 떨어지고 너무 많은 함수가 생길 수 있을 것 같아요.

그런데 레포지토리에서 도메인을 반환하는 함수에 캐시를 적용한다면
"이번에 반드시 필요하지 않은 데이터까지 한번에 조회하는 문제"가 해결될거라 생각해요.!

Comment on lines 54 to 55
assertThat(actual.sections()).extracting(SectionNameResponse::id)
.containsExactly(visibleSection1.getId(), visibleSection2.getId(), nonVisibleSection.getId());
Copy link
Contributor

Choose a reason for hiding this comment

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

이름을 검증하는 것이 비즈니스 로직이니, 함께 검증하면 좋겠습니다. 이번에는 Repository에 저장하기 전에 이름을 미리 가지고 있다가 이후에 검증하면 어떨까요? 픽스처를 사용하지 않는 것도 하나의 방법이 되겠습니다~!

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
Contributor

@donghoony donghoony left a comment

Choose a reason for hiding this comment

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

image

테스트 깨지네요 ㅎㅎ.., RC 드립니다

Copy link
Contributor

@donghoony donghoony left a comment

Choose a reason for hiding this comment

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

한가지 테스트에서 이야기하고 싶은게 있어용~ 어프룹 드립니다 :+1

Comment on lines 55 to 57
assertThat(actual.sections()).extracting(SectionNameResponse::name)
.containsExactly(visibleSection1.getSectionName(), visibleSection2.getSectionName(),
nonVisibleSection.getSectionName());
Copy link
Contributor

Choose a reason for hiding this comment

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

Repository에 저장한 걸로 검증하는 거라, 조금 더 명확하게 할 거면 저장하기 전에 섹션 이름을 미리 뽑아 놓고 검증하는 게 더 알맞으려나요? 🤔

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
Contributor

@skylar1220 skylar1220 left a comment

Choose a reason for hiding this comment

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

테드 짱빠룸!!

Copy link
Contributor

@nayonsoso nayonsoso left a comment

Choose a reason for hiding this comment

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

image

구구구구굳..!

@Kimprodp Kimprodp merged commit 41d8c66 into develop Oct 11, 2024
5 checks passed
@donghoony donghoony deleted the be/feat/797-section-name-list branch October 11, 2024 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[BE] feat: 섹션 이름 목록 조회 API를 구현한다.
4 participants