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

Newsletter 패키지 구조 리팩터링 #125

Merged
merged 6 commits into from
Feb 28, 2025
Merged

Conversation

patulus
Copy link
Contributor

@patulus patulus commented Feb 26, 2025

🌱 작업 사항

  • Newsletter 도메인의 패키지 구조를 리팩터링하였습니다.
  • 리팩터링 후 구독 정보 저장, 수정, 삭제 및 메일과 디스코드 발송이 잘 진행되었음을 확인하였습니다.

❓ 리뷰 포인트

  • 레이어 의존 상태에 이상이 없는지 확인 부탁드립니다.
  • 도메인 엔티티의 클래스 이름이 적절한가요?
  • 리포지토리, 핸들러의 메서드 이름이 적절한가요?

🦄 관련 이슈

resolves #이슈번호

@patulus patulus added the ♻️ Refactor 리팩토링 label Feb 26, 2025
@kang20
Copy link
Member

kang20 commented Feb 26, 2025

📝 Jacoco Test Coverage

Overall Project NaN% NaN% 🍏

There is no coverage information present for the Files changed

Copy link

github-actions bot commented Feb 26, 2025

🧪 Test Results

53 tests  ±0   52 ✅ ±0   5s ⏱️ ±0s
19 suites ±0    1 💤 ±0 
19 files   ±0    0 ❌ ±0 

Results for commit b94b6ff. ± Comparison against base commit 3392aa3.

♻️ This comment has been updated with latest results.

@patulus patulus marked this pull request as ready for review February 26, 2025 01:59
@patulus patulus changed the title 뉴스레터 패키지 구조 리팩터링 Newsletter 패키지 구조 리팩터링 Feb 26, 2025
Copy link
Member

@kang20 kang20 left a comment

Choose a reason for hiding this comment

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

고생하셨습니다.

domain 을 다른 의존으로부터 잘 분리하신거 같아요 다만 비즈니스 영역의 코드가 infra 쪽에 validate라는 의도로 존재합니다 이부분에 대한 의견이 궁금합니다

Comment on lines 37 to 41
*/
@GetMapping("/seminar-notice-basicFrom")
public ResponseEntity<ResponseBody<SeminarNoticeBasicForm>> getSeminarNoticeBasicForm() {
return ResponseEntity.ok(createSuccessResponse(newsletterAdminService.getSeminarNoticeBasicForm()));
return ResponseEntity.ok(createSuccessResponse(new SeminarNoticeBasicForm(newsletterAdminService.getSeminarNoticeBasicForm().getHtmlContent())));
}
Copy link
Member

Choose a reason for hiding this comment

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

p5: 이건 코드 스타일 취향차이이지만 new 연산자로 객체를 생성하는거보다 static 메서드로 of 메서드 네이밍으로 생성하면 더 깔끔할거 같습니다

Copy link
Contributor Author

Choose a reason for hiding this comment

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

의견 반영하여 of 메서드를 추가하도록 하겠습니다!

Comment on lines 8 to 27
@Component
@RequiredArgsConstructor
public class NewsletterHandler {
private final NewsletterRepository newsletterRepository;

public void saveNewsletterSubscription(NewsletterSubscription newsletterSubscription) {
newsletterRepository.saveNewsletterSubscription(newsletterSubscription);
}

public void updateNewsletterSubscription(NewsletterSubscription newsletterSubscription) {
newsletterRepository.updateNewsletterSubscription(newsletterSubscription);
}

public void deleteNewsletterSubscription(String email) {
newsletterRepository.deleteNewsletterSubscription(email);
}

public void validateNewsletterSubscription(String email) {
newsletterRepository.validateNewsletterSubscription(email);
}
Copy link
Member

Choose a reason for hiding this comment

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

P3: 저번에 설명한 의도대로 구현하신거 같습니다. 다만 validate 관련 에러 핸들링을 도메인 Layer에서 하는게 더 직관적이여 보입니다. service나 implement 에서 처리하는게 옳을거 같아요

이유는 에러 또한 비즈니스 로직의 한 부분이기 때문에 에러를 핸들링하는 것 또한 도메인 로직이라 생각합니다
어떻게 생각하시나요

메서드 이름이 validate라면 해당 메서드에서 처리하는게 좋아보이네요

Copy link
Contributor Author

Choose a reason for hiding this comment

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

동의합니다. 도메인 레이어에서 에러 핸들링 및 검증을 할 수 있도록 수정하겠습니다.

Comment on lines 32 to 60
@Override
@Transactional
public void updateNewsletterSubscription(NewsletterSubscription newsletterSubscription) {
Newsletter newsletter = newsletterJpaRepository.findByEmail(newsletterSubscription.getEmail())
.orElseThrow(() -> new ServiceException(SUBSCRIBE_NOT_FOUND));

newsletter.updateNewsletter(newsletterSubscription.getEmail(),
newsletterSubscription.getSeminarContentNotice(),
newsletterSubscription.getStudyNotice(),
newsletterSubscription.getProjectNotice(),
newsletterSubscription.getMentoringNotice());
}

@Override
@Transactional
public void deleteNewsletterSubscription(String email) {
Newsletter newsletter = newsletterJpaRepository.findByEmail(email)
.orElseThrow(() -> new ServiceException(SUBSCRIBE_NOT_FOUND));

newsletterJpaRepository.delete(newsletter);
}

@Override
public void validateNewsletterSubscription(String email) {
if (newsletterJpaRepository.existsByEmail(email)) {
throw new ServiceException(SUBSCRIBE_EMAIL_CONFLICT);
}
}

Copy link
Member

Choose a reason for hiding this comment

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

p3: validate 로직이 전부 해당 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.

확실히 Repository에서 검증을 처리하는게 어색하네요. 수정하겠습니다.

Copy link
Contributor

@siwan9 siwan9 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

@kimgunwooo kimgunwooo 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 14 to 22
@RequiredArgsConstructor
public class NewsletterEventPublisher {
private final NewsletterRepository newsletterRepository;
private final EmailService emailService;
private final ApplicationEventPublisher applicationEventPublisher;

public void publish(EmailNotificationEvent event) {
applicationEventPublisher.publishEvent(event);
}
Copy link
Contributor

@kimgunwooo kimgunwooo Feb 27, 2025

Choose a reason for hiding this comment

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

P5 : NewsletterEventPublisher 라는 class에 EventListener가 같이 있는게 조금 어색한 것 같아 보입니다. SRP에 따라 한 클래스는 하나의 책임만 갖는건 어떤가요?? applicationEventPublisher.publishEvent 도입 자체는 좋아보입니다!! 대신 의존성 주입없이 사용할 수 있게 static 메서드로 사용해도 괜찮아 보입니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

단일 책임 원칙에 따라 하나의 책임만 가질 수 있도록 NewsletterEventPublisher와 NewsletterEventListener로 분리하겠습니다!

Copy link
Contributor

@kon28289 kon28289 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
Member

@kang20 kang20 left a comment

Choose a reason for hiding this comment

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

고생하셨습니다 develop 브랜치 merge 하여 충돌 해결 후 push 해주세요

@patulus patulus merged commit 0195e48 into develop Feb 28, 2025
4 checks passed
@patulus patulus deleted the feat/refactor-newsletter branch February 28, 2025 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
♻️ Refactor 리팩토링
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants