Skip to content

Commit

Permalink
๐Ÿ”— :: (809) ๋ชจ์ง‘์˜๋ขฐ์„œ ์ƒํƒœ ๋ณ€๊ฒฝ ์Šค์ผ€์ค„๋Ÿฌ ์ˆ˜์ •
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyoil2 authored Nov 22, 2024
2 parents 347ed35 + 9cc33fe commit 30df51b
Showing 5 changed files with 29 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -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 recruitment;

}
Original file line number Diff line number Diff line change
@@ -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;
@@ -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() {
Original file line number Diff line number Diff line change
@@ -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;

@@ -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
@@ -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);
Original file line number Diff line number Diff line change
@@ -9,13 +9,11 @@
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.spi.QueryUserPort;
import team.retum.jobis.thirdparty.fcm.FCMUtil;
@@ -60,34 +58,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.getRecruitment().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.getRecruitment().getId())
.topic(Topic.WINTER_INTERN)
.authority(Authority.STUDENT)
.isNew(true)
.build();

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

0 comments on commit 30df51b

Please sign in to comment.