Skip to content
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

πŸ”— :: (#857) λ°˜λ €μ‹œ μ•Œλ¦Ό μΆ”κ°€ #860

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
4mjeo marked this conversation as resolved.
Show resolved Hide resolved
}
}
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())
);
}
}
Loading