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()) + ); + } }