-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor/#62: 문의/음악 추천 알림 이벤트와 리스너 생성 * refactor/#62: 문의/음악 추천 서비스에서 이벤트 발행 * refactor/#62: NotificationService 생성 및 테스트 코드 수정 * refactor/#62: 문의/음악 추천 인수 테스트 수정
- Loading branch information
1 parent
bad7856
commit 54e694d
Showing
27 changed files
with
322 additions
and
106 deletions.
There are no files selected for viewing
8 changes: 0 additions & 8 deletions
8
src/main/java/com/verby/indp/domain/common/event/MailSendEvent.java
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
src/main/java/com/verby/indp/domain/contact/event/ContactMailEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.verby.indp.domain.contact.event; | ||
|
||
import com.verby.indp.domain.notification.dto.ContactMail; | ||
|
||
public record ContactMailEvent( | ||
ContactMail request | ||
) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.verby.indp.domain.mail.dto; | ||
|
||
import com.verby.indp.domain.notification.MailNotification; | ||
|
||
public record Mail( | ||
long id, | ||
String to, | ||
String subject, | ||
String text | ||
) { | ||
|
||
public static Mail from(MailNotification notification) { | ||
return new Mail( | ||
notification.getMailNotificationId(), | ||
notification.getReceiverEmail(), | ||
notification.getSubject(), | ||
notification.getText() | ||
); | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/verby/indp/domain/mail/service/MailService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.verby.indp.domain.mail.service; | ||
|
||
import com.verby.indp.domain.mail.dto.Mail; | ||
|
||
public interface MailService { | ||
|
||
void sendMail(Mail mail); | ||
|
||
} |
11 changes: 6 additions & 5 deletions
11
...otification/service/MailSendListener.java → ...domain/mail/service/SendMailListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,22 @@ | ||
package com.verby.indp.domain.notification.service; | ||
package com.verby.indp.domain.mail.service; | ||
|
||
import static org.springframework.transaction.event.TransactionPhase.AFTER_COMMIT; | ||
|
||
import com.verby.indp.domain.common.event.MailSendEvent; | ||
import com.verby.indp.domain.notification.event.SendMailEvent; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.event.TransactionalEventListener; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class MailSendListener { | ||
public class SendMailListener { | ||
|
||
private final MailService mailService; | ||
|
||
@Async | ||
@TransactionalEventListener(phase = AFTER_COMMIT) | ||
public void handleMailSendEvent(MailSendEvent event) { | ||
public void handleSendMailEvent(SendMailEvent event) { | ||
mailService.sendMail(event.mail()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/com/verby/indp/domain/notification/dto/ContactMail.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.verby.indp.domain.notification.dto; | ||
|
||
public record ContactMail( | ||
String to, | ||
String content, | ||
String userName, | ||
String phoneNumber | ||
) { | ||
|
||
public static ContactMail of( | ||
String to, | ||
String content, | ||
String userName, | ||
String phoneNumber | ||
) { | ||
return new ContactMail(to, content, userName, phoneNumber); | ||
} | ||
|
||
} |
9 changes: 0 additions & 9 deletions
9
src/main/java/com/verby/indp/domain/notification/dto/Mail.java
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
src/main/java/com/verby/indp/domain/notification/dto/RecommendationMail.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.verby.indp.domain.notification.dto; | ||
|
||
public record RecommendationMail( | ||
String to, | ||
String information, | ||
String phoneNumber, | ||
String storeName, | ||
String storeAddress | ||
) { | ||
public static RecommendationMail of( | ||
String to, | ||
String information, | ||
String phoneNumber, | ||
String storeName, | ||
String storeAddress | ||
) { | ||
return new RecommendationMail(to, information, phoneNumber, storeName, storeAddress); | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/verby/indp/domain/notification/event/SendMailEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.verby.indp.domain.notification.event; | ||
|
||
import com.verby.indp.domain.mail.dto.Mail; | ||
|
||
public record SendMailEvent(Mail mail) { | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/verby/indp/domain/notification/repository/NotificationRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.verby.indp.domain.notification.repository; | ||
|
||
import com.verby.indp.domain.notification.MailNotification; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface NotificationRepository extends JpaRepository<MailNotification, Long> { | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/verby/indp/domain/notification/service/ContactMailListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.verby.indp.domain.notification.service; | ||
|
||
import static org.springframework.transaction.event.TransactionPhase.AFTER_COMMIT; | ||
|
||
import com.verby.indp.domain.contact.event.ContactMailEvent; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.event.TransactionalEventListener; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ContactMailListener { | ||
|
||
private final NotificationService notificationService; | ||
|
||
@Async | ||
@TransactionalEventListener(phase = AFTER_COMMIT) | ||
public void handleContactMailEvent(ContactMailEvent event) { | ||
notificationService.sendContactMail(event.request()); | ||
} | ||
|
||
} |
9 changes: 0 additions & 9 deletions
9
src/main/java/com/verby/indp/domain/notification/service/MailService.java
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
src/main/java/com/verby/indp/domain/notification/service/NotificationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.verby.indp.domain.notification.service; | ||
|
||
import com.verby.indp.domain.notification.MailNotification; | ||
import com.verby.indp.domain.mail.dto.Mail; | ||
import com.verby.indp.domain.notification.dto.ContactMail; | ||
import com.verby.indp.domain.notification.dto.RecommendationMail; | ||
import com.verby.indp.domain.notification.event.SendMailEvent; | ||
import com.verby.indp.domain.notification.repository.NotificationRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.ApplicationEventPublisher; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class NotificationService { | ||
|
||
private final NotificationRepository notificationRepository; | ||
private final ApplicationEventPublisher applicationEventPublisher; | ||
|
||
@Transactional | ||
public void sendContactMail(ContactMail request) { | ||
MailNotification mailNotification = new MailNotification("[버비] 문의가 들어왔어요!", | ||
"문의 내용: " + request.content() + "\n" + | ||
"문의자 성함: " + request.userName() + "\n" + | ||
"문의자 연락처: " + request.phoneNumber() + "\n", request.to()); | ||
MailNotification persistMailNotification = notificationRepository.save(mailNotification); | ||
sendMail(persistMailNotification); | ||
} | ||
|
||
@Transactional | ||
public void sendRecommendationMail(RecommendationMail request) { | ||
MailNotification mailNotification = new MailNotification("[버비] 인디피 서비스에 음악이 추천되었어요!", | ||
"추천 음악 정보: " + request.information() + "\n" + | ||
"추천인 연락처: " + request.phoneNumber() + "\n" + | ||
"매장 이름: " + request.storeName() + "\n" + | ||
"매장 주소: " + request.storeAddress() + "\n", request.to()); | ||
MailNotification persistMailNotification = notificationRepository.save(mailNotification); | ||
sendMail(persistMailNotification); | ||
} | ||
|
||
private void sendMail(MailNotification persistMailNotification) { | ||
Mail mail = Mail.from(persistMailNotification); | ||
applicationEventPublisher.publishEvent(new SendMailEvent(mail)); | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/verby/indp/domain/notification/service/RecommendationMailListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.verby.indp.domain.notification.service; | ||
|
||
import static org.springframework.transaction.event.TransactionPhase.AFTER_COMMIT; | ||
|
||
import com.verby.indp.domain.recommendation.event.RecommendationMailEvent; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.event.TransactionalEventListener; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class RecommendationMailListener { | ||
|
||
private final NotificationService notificationService; | ||
|
||
@Async | ||
@TransactionalEventListener(phase = AFTER_COMMIT) | ||
public void handleRecommendationMailEvent(RecommendationMailEvent event) { | ||
notificationService.sendRecommendationMail(event.request()); | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/verby/indp/domain/recommendation/event/RecommendationMailEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.verby.indp.domain.recommendation.event; | ||
|
||
import com.verby.indp.domain.notification.dto.RecommendationMail; | ||
|
||
public record RecommendationMailEvent( | ||
RecommendationMail request | ||
) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 0 additions & 13 deletions
13
src/main/java/com/verby/indp/global/config/AsyncConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,10 @@ | ||
package com.verby.indp.global.config; | ||
|
||
import java.util.concurrent.Executor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.annotation.EnableAsync; | ||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
|
||
@EnableAsync | ||
@Configuration | ||
public class AsyncConfig { | ||
|
||
@Bean(name = "asyncEmailSendExecutor") | ||
public Executor asyncEmailSendExecutor() { | ||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); | ||
executor.setCorePoolSize(2); | ||
executor.setMaxPoolSize(10); | ||
executor.setQueueCapacity(100); | ||
executor.setThreadNamePrefix("Executor-"); | ||
return executor; | ||
} | ||
|
||
} |
Oops, something went wrong.