From 319e137fbd85a22836872d0b35617f26c88e554e Mon Sep 17 00:00:00 2001 From: "tae.y" <0211ilyoil@gmail.com> Date: Wed, 20 Nov 2024 19:15:28 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=A7=A9=20::=20(#857)=20=EB=B0=98?= =?UTF-8?q?=EB=A0=A4=EC=8B=9C=20=EC=95=8C=EB=A6=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SingleApplicationStatusChangedEvent.java | 14 +++++++++++ .../usecase/RejectApplicationUseCase.java | 9 ++++--- .../application/ApplicationEventHandler.java | 25 ++++++++++++++++++- 3 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 jobis-application/src/main/java/team/retum/jobis/domain/application/event/SingleApplicationStatusChangedEvent.java diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/application/event/SingleApplicationStatusChangedEvent.java b/jobis-application/src/main/java/team/retum/jobis/domain/application/event/SingleApplicationStatusChangedEvent.java new file mode 100644 index 000000000..b3daf81a9 --- /dev/null +++ b/jobis-application/src/main/java/team/retum/jobis/domain/application/event/SingleApplicationStatusChangedEvent.java @@ -0,0 +1,14 @@ +package team.retum.jobis.domain.application.event; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import team.retum.jobis.domain.application.model.Application; +import team.retum.jobis.domain.application.model.ApplicationStatus; + +@Getter +@AllArgsConstructor +public class SingleApplicationStatusChangedEvent { + + private final Application application; + private final ApplicationStatus status; +} diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/application/usecase/RejectApplicationUseCase.java b/jobis-application/src/main/java/team/retum/jobis/domain/application/usecase/RejectApplicationUseCase.java index e78b16046..fb93fa5b2 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/application/usecase/RejectApplicationUseCase.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/application/usecase/RejectApplicationUseCase.java @@ -2,7 +2,10 @@ import lombok.RequiredArgsConstructor; import team.retum.jobis.common.annotation.UseCase; +import team.retum.jobis.common.spi.PublishEventPort; +import team.retum.jobis.domain.application.event.SingleApplicationStatusChangedEvent; import team.retum.jobis.domain.application.model.Application; +import team.retum.jobis.domain.application.model.ApplicationStatus; import team.retum.jobis.domain.application.spi.CommandApplicationPort; import team.retum.jobis.domain.application.spi.QueryApplicationPort; @@ -12,12 +15,12 @@ public class RejectApplicationUseCase { private final QueryApplicationPort queryApplicationPort; private final CommandApplicationPort commandApplicationPort; + private final PublishEventPort publishEventPort; public void execute(Long applicationId, String rejectReason) { Application application = queryApplicationPort.getByIdOrThrow(applicationId); - commandApplicationPort.save( - application.rejectApplication(rejectReason) - ); + publishEventPort.publishEvent(new SingleApplicationStatusChangedEvent(application, ApplicationStatus.REJECTED)); + commandApplicationPort.save(application.rejectApplication(rejectReason)); } } diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/event/application/ApplicationEventHandler.java b/jobis-infrastructure/src/main/java/team/retum/jobis/event/application/ApplicationEventHandler.java index d5ae14801..0f2bc4ece 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/event/application/ApplicationEventHandler.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/event/application/ApplicationEventHandler.java @@ -5,6 +5,7 @@ import org.springframework.stereotype.Component; import org.springframework.transaction.event.TransactionPhase; import org.springframework.transaction.event.TransactionalEventListener; +import team.retum.jobis.domain.application.event.SingleApplicationStatusChangedEvent; import team.retum.jobis.domain.application.event.ApplicationsStatusChangedEvent; import team.retum.jobis.domain.application.model.Application; import team.retum.jobis.domain.application.model.ApplicationStatus; @@ -32,7 +33,7 @@ public class ApplicationEventHandler { @Async("asyncTaskExecutor") @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) - public void onApplicationStatusChanged(ApplicationsStatusChangedEvent event) { + public void onSingleApplicationStatusChanged(ApplicationsStatusChangedEvent event) { if (event.getStatus() == ApplicationStatus.PROCESSING) { return; } @@ -70,4 +71,26 @@ public void onApplicationStatusChanged(ApplicationsStatusChangedEvent event) { ); } } + + @Async("asyncTaskExecutor") + @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) + public void onApplicationStatusChange(SingleApplicationStatusChangedEvent event) { + User user = queryUserPort.getByStudentId(event.getApplication().getStudentId()); + + Notification notification = Notification.builder() + .title("결과 보러가기") + .content("지원서 상태가 " + event.getStatus().getName() + "으로 변경되었습니다.") + .userId(event.getApplication().getStudentId()) + .topic(Topic.APPLICATION) + .detailId(event.getApplication().getId()) + .authority(Authority.STUDENT) + .isNew(true) + .build(); + + commandNotificationPort.save(notification); + fcmUtil.sendMessages( + notification, + List.of(user.getToken()) + ); + } } From 844c8cc79139a92c223177f94ef75366724d7721 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=A7=84?= <4mj.eo@dsm.hs.kr> Date: Thu, 21 Nov 2024 15:38:57 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=9B=A0=20::=20(#856)=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=BB=A8=EB=B2=A4=EC=85=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/application/usecase/RejectApplicationUseCase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/application/usecase/RejectApplicationUseCase.java b/jobis-application/src/main/java/team/retum/jobis/domain/application/usecase/RejectApplicationUseCase.java index fb93fa5b2..d5df01f95 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/application/usecase/RejectApplicationUseCase.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/application/usecase/RejectApplicationUseCase.java @@ -20,7 +20,7 @@ public class RejectApplicationUseCase { public void execute(Long applicationId, String rejectReason) { Application application = queryApplicationPort.getByIdOrThrow(applicationId); - publishEventPort.publishEvent(new SingleApplicationStatusChangedEvent(application, ApplicationStatus.REJECTED)); commandApplicationPort.save(application.rejectApplication(rejectReason)); + publishEventPort.publishEvent(new SingleApplicationStatusChangedEvent(application, ApplicationStatus.REJECTED)); } }