Skip to content

Commit

Permalink
🧩 :: (#857) 반려시 알림 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyoil2 committed Nov 20, 2024
1 parent e2aac97 commit 319e137
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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())
);
}
}

0 comments on commit 319e137

Please sign in to comment.