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

πŸ”— :: (809) λͺ¨μ§‘μ˜λ’°μ„œ μƒνƒœ λ³€κ²½ μŠ€μΌ€μ€„λŸ¬ μˆ˜μ • #862

Merged
merged 5 commits into from
Nov 22, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import lombok.Getter;
import team.retum.jobis.domain.recruitment.model.Recruitment;

import java.util.List;

@Getter
@AllArgsConstructor
public class WinterInternRegisteredEvent {

private final List<Recruitment> recruitments;
private final Recruitment recruitments;
ilyoil2 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 team.retum.jobis.common.spi.PublishEventPort;
import team.retum.jobis.common.spi.SecurityPort;
import team.retum.jobis.domain.company.model.Company;
import team.retum.jobis.domain.intern.event.WinterInternRegisteredEvent;
import team.retum.jobis.domain.recruitment.dto.request.ApplyRecruitmentRequest;
import team.retum.jobis.domain.recruitment.event.InterestedRecruitmentEvent;
import team.retum.jobis.domain.recruitment.exception.RecruitmentAlreadyExistsException;
Expand Down Expand Up @@ -40,7 +41,7 @@ public void execute(ApplyRecruitmentRequest request) {
.toList();
commandRecruitAreaPort.saveAll(recruitAreas);

publishEventPort.publishEvent(new InterestedRecruitmentEvent(recruitment));
publishEventPort.publishEvent(new WinterInternRegisteredEvent(recruitment));
}

public void executeInterestCodeMatch() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import team.retum.jobis.common.annotation.UseCase;
import team.retum.jobis.common.spi.PublishEventPort;
import team.retum.jobis.domain.recruitment.event.RecruitmentStatusChangedEvent;
import team.retum.jobis.domain.intern.event.WinterInternRegisteredEvent;
import team.retum.jobis.domain.recruitment.model.Recruitment;
import team.retum.jobis.domain.recruitment.spi.RecruitmentPort;

Expand All @@ -20,18 +19,11 @@ public class ChangeRecruitmentStatusSchedulerUseCase {
public void execute() {
List<Recruitment> recruitments = recruitmentPort.getAll();

List<Recruitment> updatedRecruitments = recruitments.stream()
.map(Recruitment::updateRecruitmentStatus)
.toList();

List<Recruitment> winterInternRecruitments = updatedRecruitments.stream()
.filter(Recruitment::isWinterIntern)
.toList();

publishEventPort.publishEvent(new RecruitmentStatusChangedEvent(updatedRecruitments));

if (!winterInternRecruitments.isEmpty()) {
publishEventPort.publishEvent(new WinterInternRegisteredEvent(winterInternRecruitments));
}
recruitmentPort.saveAll(
recruitments.stream()
.map(Recruitment::updateRecruitmentStatus)
.toList()
);
publishEventPort.publishEvent(new RecruitmentStatusChangedEvent(recruitments));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public class NotificationWebAdapter {
private final SubscribeAllTopicsByToggleUseCase subscribeAllTopicsByToggleUseCase;
private final QueryTopicsUseCase queryTopicsUseCase;


@GetMapping
public QueryNotificationsResponse queryNotifications(@RequestParam(value = "is_new", required = false) Boolean isNew) {
return queryNotificationsUseCase.execute(isNew);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
import team.retum.jobis.domain.company.exception.CompanyNotFoundException;
import team.retum.jobis.domain.company.model.Company;
import team.retum.jobis.domain.company.spi.QueryCompanyPort;
import team.retum.jobis.domain.intern.event.WinterInternRegisteredEvent;
import team.retum.jobis.domain.intern.event.WinterInternToggledEvent;
import team.retum.jobis.domain.notification.model.Notification;
import team.retum.jobis.domain.notification.model.Topic;
import team.retum.jobis.domain.notification.spi.CommandNotificationPort;
import team.retum.jobis.domain.intern.event.WinterInternRegisteredEvent;
import team.retum.jobis.domain.recruitment.model.RecruitStatus;
import team.retum.jobis.domain.recruitment.model.Recruitment;
import team.retum.jobis.domain.user.model.User;
import team.retum.jobis.domain.user.persistence.repository.UserJpaRepository;
import team.retum.jobis.domain.user.spi.QueryUserPort;
import team.retum.jobis.thirdparty.fcm.FCMUtil;

Expand All @@ -30,6 +29,7 @@ public class WinterInternEventHandler {
private final CommandNotificationPort commandNotificationPort;
private final QueryUserPort queryUserPort;
private final QueryCompanyPort queryCompanyPort;
private final UserJpaRepository userJpaRepository;

@Async("asyncTaskExecutor")
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
Expand Down Expand Up @@ -60,34 +60,28 @@ public void onWinterInternToggled(WinterInternToggledEvent event) {
@Async("asyncTaskExecutor")
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
public void onWinterInternRegistered(WinterInternRegisteredEvent event) {
List<Recruitment> recruitments = event.getRecruitments();

for (Recruitment recruitment : recruitments) {
if (recruitment.isWinterIntern() && recruitment.getStatus() == RecruitStatus.RECRUITING) {
List<String> deviceTokens = queryUserPort.getDeviceTokenByTopic(Topic.WINTER_INTERN);

Company company = queryCompanyPort.getById(recruitment.getCompanyId())
.orElseThrow(() -> CompanyNotFoundException.EXCEPTION);
List<String> deviceTokens = queryUserPort.getDeviceTokenByTopic(Topic.WINTER_INTERN);

String companyName = company.getName();
Company company = queryCompanyPort.getById(event.getRecruitments().getCompanyId())
.orElseThrow(() -> CompanyNotFoundException.EXCEPTION);

deviceTokens.forEach(deviceToken -> {
User user = queryUserPort.getUserIdByDeviceToken(deviceToken);
String companyName = company.getName();

Notification notification = Notification.builder()
.title(companyName + " 겨울 인턴십 λͺ¨μ§‘ 곡고 ⛄️")
.content("겨울 인턴십 λͺ¨μ§‘ μ˜λ’°μ„œκ°€ λ“±λ‘λ˜μ—ˆμ–΄μš”. μ§€κΈˆ ν™•μΈν•΄λ³΄μ„Έμš”!")
.userId(user.getId())
.detailId(recruitment.getId())
.topic(Topic.WINTER_INTERN)
.authority(Authority.STUDENT)
.isNew(true)
.build();
for (String deviceToken : deviceTokens) {
User user = queryUserPort.getUserIdByDeviceToken(deviceToken);

commandNotificationPort.save(notification);
fcmUtil.sendMessageToTopic(notification);
});
}
Notification notification = Notification.builder()
.title(companyName + " 겨울 인턴십 λͺ¨μ§‘ 곡고 ⛄️")
.content("겨울 인턴십 λͺ¨μ§‘ μ˜λ’°μ„œκ°€ λ“±λ‘λ˜μ—ˆμ–΄μš”. μ§€κΈˆ ν™•μΈν•΄λ³΄μ„Έμš”!")
.userId(user.getId())
.detailId(event.getRecruitments().getId())
.topic(Topic.WINTER_INTERN)
.authority(Authority.STUDENT)
.isNew(true)
.build();

commandNotificationPort.save(notification);
fcmUtil.sendMessageToTopic(notification);
}
}
}
Loading