-
Notifications
You must be signed in to change notification settings - Fork 0
[Quiz][Refactor] 퀴즈 생성 중 타유저가 생성요청 보내더라도 타유저에게 퀴즈 생성 완료 알림을 보낸다 #203
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
Changes from all commits
df4c8e5
1f6b382
7885ddc
7975706
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package book.book.quiz.domain; | ||
|
|
||
| import book.book.common.BaseTimeEntity; | ||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.GeneratedValue; | ||
| import jakarta.persistence.GenerationType; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.Table; | ||
| import jakarta.persistence.UniqueConstraint; | ||
| import lombok.AccessLevel; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @Table(name = "quiz_subscriber", uniqueConstraints = { | ||
| @UniqueConstraint(name = "uk_quiz_subscriber_book_member", columnNames = {"book_id", "member_id"}) | ||
| }) | ||
| public class QuizSubscriber extends BaseTimeEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| private Long bookId; | ||
|
|
||
| private Long memberId; | ||
|
|
||
| @Builder | ||
| public QuizSubscriber(Long bookId, Long memberId) { | ||
| this.bookId = bookId; | ||
| this.memberId = memberId; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package book.book.quiz.repository; | ||
|
|
||
| import book.book.quiz.domain.QuizSubscriber; | ||
| import java.util.List; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.data.jpa.repository.Modifying; | ||
| import org.springframework.data.jpa.repository.Query; | ||
|
|
||
| public interface QuizSubscriberRepository extends JpaRepository<QuizSubscriber, Long> { | ||
|
|
||
| List<QuizSubscriber> findAllByBookId(Long bookId); | ||
|
|
||
| @Modifying | ||
| @Query("DELETE FROM QuizSubscriber qs WHERE qs.bookId = :bookId") | ||
| void deleteAllByBookId(Long bookId); | ||
|
|
||
| boolean existsByBookIdAndMemberId(Long bookId, Long memberId); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,14 +5,17 @@ | |
| import book.book.common.CustomException; | ||
| import book.book.common.ErrorCode; | ||
| import book.book.quiz.domain.QuizStatus; | ||
| import book.book.quiz.domain.QuizSubscriber; | ||
| import book.book.quiz.dto.external.GeminiQuizResponses; | ||
| import book.book.quiz.event.QuizCreatedEvent; | ||
| import book.book.quiz.repository.QuizSubscriberRepository; | ||
| import java.util.List; | ||
| import java.util.concurrent.CompletionException; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.context.ApplicationEventPublisher; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Slf4j | ||
| @Service | ||
|
|
@@ -22,18 +25,26 @@ public class QuizGenerationHandlerService { | |
| private final QuizSaveService quizSaveService; | ||
| private final ApplicationEventPublisher eventPublisher; | ||
| private final QuizAlertService quizAlertService; | ||
| private final QuizSubscriberRepository quizSubscriberRepository; | ||
|
|
||
| public void handleSuccess(Book book, List<Chapter> chapters, GeminiQuizResponses batchResponse, Long memberId) { | ||
| @Transactional | ||
| public void handleSuccess(Book book, List<Chapter> chapters, GeminiQuizResponses batchResponse) { | ||
| List<Long> chapterIds = chapters.stream().map(Chapter::getId).toList(); | ||
|
|
||
| quizSaveService.saveQuizzesBatchAndUpdateStatus( | ||
| book.getId(), | ||
| chapterIds, | ||
| batchResponse); | ||
|
|
||
| if (memberId != null) { | ||
| eventPublisher.publishEvent(new QuizCreatedEvent(book.getId(), memberId)); | ||
| sendEventToAllRequesters(book); | ||
| } | ||
|
|
||
| private void sendEventToAllRequesters(Book book) { | ||
| List<QuizSubscriber> subscribers = quizSubscriberRepository.findAllByBookId(book.getId()); | ||
| for (QuizSubscriber subscriber : subscribers) { | ||
| eventPublisher.publishEvent(new QuizCreatedEvent(book.getId(), subscriber.getMemberId())); | ||
| } | ||
| quizSubscriberRepository.deleteAllByBookId(book.getId()); | ||
| } | ||
|
Comment on lines
+42
to
48
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 퀴즈 생성 완료 후 모든 구독자에게 알림을 보내는 로직이 추가되었네요. 한 가지 고려할 점은 예를 들어, |
||
|
|
||
| public void handleFailure(Book book, Throwable ex) { | ||
|
|
||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.