Skip to content

Commit

Permalink
๐Ÿ›  :: (#809) ๊ฒจ์šธ์ธํ„ด ์•Œ๋ฆผ ์ˆ˜์ •
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyoil2 committed Nov 21, 2024
1 parent d8614bf commit aa414fe
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
package team.retum.jobis.domain.intern.event;

import lombok.AllArgsConstructor;
import lombok.Getter;
import team.retum.jobis.domain.recruitment.model.Recruitment;

@Getter
@AllArgsConstructor
public class SingleWinterInternRegisteredEvent {

private final Recruitment recruitments;

}
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.SingleWinterInternRegisteredEvent;
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 SingleWinterInternRegisteredEvent(recruitment));
}

public void executeInterestCodeMatch() {
Expand Down
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,6 +9,7 @@
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.SingleWinterInternRegisteredEvent;
import team.retum.jobis.domain.intern.event.WinterInternToggledEvent;
import team.retum.jobis.domain.notification.model.Notification;
import team.retum.jobis.domain.notification.model.Topic;
Expand All @@ -17,6 +18,7 @@
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 +32,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 @@ -90,4 +93,32 @@ public void onWinterInternRegistered(WinterInternRegisteredEvent event) {
}
}
}

@Async("asyncTaskExecutor")
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
public void onSingleWinterInternRegistered(SingleWinterInternRegisteredEvent event) {
List<String> deviceTokens = queryUserPort.getDeviceTokenByTopic(Topic.WINTER_INTERN);

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

String companyName = company.getName();

for (String deviceToken : deviceTokens) {
User user = queryUserPort.getUserIdByDeviceToken(deviceToken);

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

0 comments on commit aa414fe

Please sign in to comment.