-
Notifications
You must be signed in to change notification settings - Fork 0
Feat : 동아리 구독 추가/삭제, 구독자 알림 기능 추가 #346
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
Merged
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
c17eef8
feat : Club Equals & HashCode 오버라이딩
rlagkswn00 e749bc9
feat : KuringFeatures 추가
rlagkswn00 92a1cb3
feat : Club MessageType 추가
rlagkswn00 2654d73
feat : 사용자 동아리 즐겨찾기 추가/삭제 API Adapter추가
rlagkswn00 22ee698
feat : 동아리 즐겨찾기 Request & Command 추가
rlagkswn00 eced9a7
feat : 동아리 즐겨찾기 Usecase & Service 추가
rlagkswn00 7d71d7b
feat : Club & ClubSubscribe Query & CommandPort 추가
rlagkswn00 603c415
feat : Club & ClubSubscribe Repository추가
rlagkswn00 9a52932
feat : ClubQueryRepository & Impl 추가
rlagkswn00 8d99247
feat : ClubPersistenceAdapter 추가
rlagkswn00 ce4d84b
feat : ClubSubscribe RootUser Mapping 수정
rlagkswn00 ecd0675
feat : ClubNotificationUseCase & Service 추가
rlagkswn00 10f515d
feat : ClubNotificationScheduler 추가
rlagkswn00 37637de
feat : Club ErrorCode & ResponseCodeAndMessages 추가
rlagkswn00 91a8a6f
feat : Club 구독 응답 DTO 추가
rlagkswn00 4dfcf1c
feat : ClubSubscribe user -> rootUser 매핑 변경
rlagkswn00 f9da2b2
feat : 사용자 구독 추가/취소 인수테스트 추가
rlagkswn00 48713eb
feat : Club 도메인 DependencyRuleTests 추가
rlagkswn00 12b40bd
feat : DatabaseConfigurator 동아리 init 추가
rlagkswn00 c977cd3
feat : ClubPersistenceAdapterTest 추가
rlagkswn00 6e74eb7
feat : ClubNotificationServiceTest 추가
rlagkswn00 41cb159
feat : ClubNotificationSchedulerTest 추가
rlagkswn00 fe5b53a
feat : ClubCommandServiceTest 추가
rlagkswn00 82d5b30
test : ClubPersistenceAdapterTest 테스트 간소화
rlagkswn00 73f1e9e
test : ClubServiceTest 리팩토링
rlagkswn00 3381306
test : Club Service & Adapter Test assertAll 처리
rlagkswn00 89a11c5
test: 미사용 메서드 제거
rlagkswn00 a1d8f2a
remove: 미사용 Enum 제거
rlagkswn00 a03fcca
fix : 동아리 즐겨찾기 삭제 API Request형식 수정
rlagkswn00 d3a889d
fix : 동아리 즐겨찾기 추가/삭제 시 dev suffix추가하도록 수정
rlagkswn00 b690281
test : ServerProperties Mock 추가
rlagkswn00 e5bbf27
remove : 미사용 메서드 제거(equals, hashcode)
rlagkswn00 0673a53
fix : JWT static final String 으로 분리
rlagkswn00 23496af
fix : club_subscribe 테이블 root_user_id로 컬럼 변경 시 기존 데이터 무시
rlagkswn00 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
src/main/java/com/kustacks/kuring/club/adapter/out/persistence/ClubPersistenceAdapter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package com.kustacks.kuring.club.adapter.out.persistence; | ||
|
|
||
| import com.kustacks.kuring.club.application.port.out.ClubQueryPort; | ||
| import com.kustacks.kuring.club.application.port.out.ClubSubscriptionCommandPort; | ||
| import com.kustacks.kuring.club.application.port.out.ClubSubscriptionQueryPort; | ||
| import com.kustacks.kuring.club.domain.Club; | ||
| import com.kustacks.kuring.club.domain.ClubSubscribe; | ||
| import com.kustacks.kuring.common.annotation.PersistenceAdapter; | ||
| import com.kustacks.kuring.user.domain.RootUser; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.time.LocalDateTime; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| @PersistenceAdapter | ||
| @RequiredArgsConstructor | ||
| public class ClubPersistenceAdapter implements ClubQueryPort, ClubSubscriptionCommandPort, ClubSubscriptionQueryPort { | ||
|
|
||
| private final ClubRepository clubRepository; | ||
| private final ClubSubscribeRepository clubSubscribeRepository; | ||
|
|
||
| @Override | ||
| public Optional<Club> findClubById(Long id) { | ||
| return clubRepository.findById(id); | ||
| } | ||
|
|
||
| @Override | ||
| public List<Club> findClubsBetweenDates(LocalDateTime start, LocalDateTime end) { | ||
| return clubRepository.findClubsBetweenDates(start, end); | ||
| } | ||
|
|
||
| @Override | ||
| public List<Club> findNextDayRecruitEndClubs(LocalDateTime now) { | ||
| LocalDate tomorrow = now.toLocalDate().plusDays(1); | ||
| LocalDateTime startInclusive = tomorrow.atStartOfDay(); | ||
| LocalDateTime endExclusive = tomorrow.plusDays(1).atStartOfDay(); | ||
| return findClubsBetweenDates(startInclusive, endExclusive); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean existsSubscription(Long rootUserId, Long clubId) { | ||
| return clubSubscribeRepository.existsByRootUserIdAndClubId(rootUserId, clubId); | ||
| } | ||
|
|
||
| @Override | ||
| public void saveSubscription(RootUser rootUser, Club club) { | ||
| clubSubscribeRepository.save(new ClubSubscribe(rootUser, club)); | ||
| } | ||
|
|
||
| @Override | ||
| public void deleteSubscription(RootUser rootUser, Club club) { | ||
| clubSubscribeRepository.deleteByRootUserAndClub(rootUser, club); | ||
| } | ||
|
|
||
| @Override | ||
| public long countSubscriptions(Long rootUserId) { | ||
| return clubSubscribeRepository.countByRootUserId(rootUserId); | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/kustacks/kuring/club/adapter/out/persistence/ClubQueryRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package com.kustacks.kuring.club.adapter.out.persistence; | ||
|
|
||
| import com.kustacks.kuring.club.domain.Club; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.List; | ||
|
|
||
| public interface ClubQueryRepository { | ||
|
|
||
| List<Club> findClubsBetweenDates(LocalDateTime start, LocalDateTime end); | ||
| } |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/kustacks/kuring/club/adapter/out/persistence/ClubQueryRepositoryImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package com.kustacks.kuring.club.adapter.out.persistence; | ||
|
|
||
| import com.kustacks.kuring.club.domain.Club; | ||
| import com.querydsl.core.types.dsl.BooleanExpression; | ||
| import com.querydsl.jpa.impl.JPAQueryFactory; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.List; | ||
|
|
||
| import static com.kustacks.kuring.club.domain.QClub.club; | ||
|
|
||
| @RequiredArgsConstructor | ||
| class ClubQueryRepositoryImpl implements ClubQueryRepository { | ||
|
|
||
| private final JPAQueryFactory queryFactory; | ||
|
|
||
| @Override | ||
| public List<Club> findClubsBetweenDates(LocalDateTime start, LocalDateTime end) { | ||
| return queryFactory.selectFrom(club) | ||
| .where( | ||
| club.isAlways.isFalse(), | ||
| recruitEndAtGoe(start), | ||
| recruitEndAtLt(end) | ||
| ) | ||
| .fetch(); | ||
| } | ||
|
|
||
| private BooleanExpression recruitEndAtGoe(LocalDateTime start) { | ||
| return start != null ? club.recruitEndAt.goe(start) : null; | ||
| } | ||
|
|
||
| private BooleanExpression recruitEndAtLt(LocalDateTime end) { | ||
| return end != null ? club.recruitEndAt.lt(end) : null; | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/kustacks/kuring/club/adapter/out/persistence/ClubRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.kustacks.kuring.club.adapter.out.persistence; | ||
|
|
||
| import com.kustacks.kuring.club.domain.Club; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| interface ClubRepository extends JpaRepository<Club, Long>, ClubQueryRepository { | ||
| } |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/kustacks/kuring/club/adapter/out/persistence/ClubSubscribeRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package com.kustacks.kuring.club.adapter.out.persistence; | ||
|
|
||
| import com.kustacks.kuring.club.domain.Club; | ||
| import com.kustacks.kuring.club.domain.ClubSubscribe; | ||
| import com.kustacks.kuring.user.domain.RootUser; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| interface ClubSubscribeRepository extends JpaRepository<ClubSubscribe, Long> { | ||
|
|
||
| boolean existsByRootUserIdAndClubId(Long rootUserId, Long clubId); | ||
|
|
||
| long countByRootUserId(Long rootUserId); | ||
|
|
||
| void deleteByRootUserAndClub(RootUser rootUser, Club club); | ||
| } |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/kustacks/kuring/club/application/port/in/ClubNotificationUseCase.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package com.kustacks.kuring.club.application.port.in; | ||
|
|
||
| public interface ClubNotificationUseCase { | ||
|
|
||
| void sendDeadlineNotifications(); | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/kustacks/kuring/club/application/port/in/ClubSubscriptionUseCase.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package com.kustacks.kuring.club.application.port.in; | ||
|
|
||
| import com.kustacks.kuring.club.application.port.in.dto.ClubSubscriptionCommand; | ||
|
|
||
| public interface ClubSubscriptionUseCase { | ||
|
|
||
| long addSubscription(ClubSubscriptionCommand command); | ||
|
|
||
| long removeSubscription(ClubSubscriptionCommand command); | ||
| } |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/kustacks/kuring/club/application/port/in/dto/ClubSubscriptionCommand.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.kustacks.kuring.club.application.port.in.dto; | ||
|
|
||
| public record ClubSubscriptionCommand( | ||
| String email, | ||
| Long clubId | ||
| ) { | ||
| } |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/kustacks/kuring/club/application/port/out/ClubQueryPort.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package com.kustacks.kuring.club.application.port.out; | ||
|
|
||
| import com.kustacks.kuring.club.domain.Club; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| public interface ClubQueryPort { | ||
|
|
||
| Optional<Club> findClubById(Long id); | ||
|
|
||
| List<Club> findClubsBetweenDates(LocalDateTime start, LocalDateTime end); | ||
|
|
||
| List<Club> findNextDayRecruitEndClubs(LocalDateTime now); | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/kustacks/kuring/club/application/port/out/ClubSubscriptionCommandPort.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package com.kustacks.kuring.club.application.port.out; | ||
|
|
||
| import com.kustacks.kuring.club.domain.Club; | ||
| import com.kustacks.kuring.user.domain.RootUser; | ||
|
|
||
| public interface ClubSubscriptionCommandPort { | ||
|
|
||
| void saveSubscription(RootUser rootUser, Club club); | ||
|
|
||
| void deleteSubscription(RootUser rootUser, Club club); | ||
| } |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/kustacks/kuring/club/application/port/out/ClubSubscriptionQueryPort.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package com.kustacks.kuring.club.application.port.out; | ||
|
|
||
| public interface ClubSubscriptionQueryPort { | ||
|
|
||
| boolean existsSubscription(Long rootUserId, Long clubId); | ||
|
|
||
| long countSubscriptions(Long rootUserId); | ||
| } |
97 changes: 97 additions & 0 deletions
97
src/main/java/com/kustacks/kuring/club/application/service/ClubCommandService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| package com.kustacks.kuring.club.application.service; | ||
|
|
||
| import com.kustacks.kuring.club.application.port.in.ClubSubscriptionUseCase; | ||
| import com.kustacks.kuring.club.application.port.in.dto.ClubSubscriptionCommand; | ||
| import com.kustacks.kuring.club.application.port.out.ClubQueryPort; | ||
| import com.kustacks.kuring.club.application.port.out.ClubSubscriptionCommandPort; | ||
| import com.kustacks.kuring.club.application.port.out.ClubSubscriptionQueryPort; | ||
| import com.kustacks.kuring.club.domain.Club; | ||
| import com.kustacks.kuring.common.annotation.UseCase; | ||
| import com.kustacks.kuring.common.exception.InvalidStateException; | ||
| import com.kustacks.kuring.common.exception.code.ErrorCode; | ||
| import com.kustacks.kuring.common.properties.ServerProperties; | ||
| import com.kustacks.kuring.user.application.port.out.RootUserQueryPort; | ||
| import com.kustacks.kuring.user.application.port.out.UserEventPort; | ||
| import com.kustacks.kuring.user.application.port.out.UserQueryPort; | ||
| import com.kustacks.kuring.user.domain.RootUser; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Slf4j | ||
| @UseCase | ||
| @Transactional | ||
| @RequiredArgsConstructor | ||
| public class ClubCommandService implements ClubSubscriptionUseCase { | ||
|
|
||
| private static final String CLUB_TOPIC_PREFIX = "club."; | ||
|
|
||
| private final ServerProperties serverProperties; | ||
| private final ClubQueryPort clubQueryPort; | ||
| private final ClubSubscriptionCommandPort clubSubscriptionCommandPort; | ||
| private final ClubSubscriptionQueryPort countSubscriptionsQueryPort; | ||
| private final RootUserQueryPort rootUserQueryPort; | ||
| private final UserQueryPort userQueryPort; | ||
| private final UserEventPort userEventPort; | ||
|
|
||
| @Override | ||
| public long addSubscription(ClubSubscriptionCommand command) { | ||
| RootUser rootUser = findRootUserByEmail(command.email()); | ||
| Club club = findClubById(command.clubId()); | ||
|
|
||
| if (isAlreadySubscription(rootUser, club)) { | ||
| throw new InvalidStateException(ErrorCode.CLUB_ALREADY_SUBSCRIBED); | ||
| } | ||
|
|
||
| clubSubscriptionCommandPort.saveSubscription(rootUser, club); | ||
| subscribeAllLoggedInDevices(rootUser.getId(), makeTopic(club)); | ||
|
|
||
| return countSubscriptionsQueryPort.countSubscriptions(rootUser.getId()); | ||
| } | ||
rlagkswn00 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @Override | ||
| public long removeSubscription(ClubSubscriptionCommand command) { | ||
| RootUser rootUser = findRootUserByEmail(command.email()); | ||
| Club club = findClubById(command.clubId()); | ||
|
|
||
| if (!isAlreadySubscription(rootUser, club)) { | ||
| throw new InvalidStateException(ErrorCode.CLUB_NOT_SUBSCRIBED); | ||
| } | ||
| clubSubscriptionCommandPort.deleteSubscription(rootUser, club); | ||
| unsubscribeAllLoggedInDevices(rootUser.getId(), makeTopic(club)); | ||
|
|
||
| return countSubscriptionsQueryPort.countSubscriptions(rootUser.getId()); | ||
| } | ||
|
|
||
| private boolean isAlreadySubscription(RootUser rootUser, Club club) { | ||
| return countSubscriptionsQueryPort.existsSubscription(rootUser.getId(), club.getId()); | ||
| } | ||
|
|
||
| private RootUser findRootUserByEmail(String email) { | ||
| return rootUserQueryPort.findRootUserByEmail(email) | ||
| .orElseThrow(() -> new InvalidStateException(ErrorCode.ROOT_USER_NOT_FOUND)); | ||
| } | ||
|
|
||
| private Club findClubById(Long id) { | ||
| return clubQueryPort.findClubById(id) | ||
| .orElseThrow(() -> new InvalidStateException(ErrorCode.CLUB_NOT_FOUND)); | ||
| } | ||
|
|
||
| private void subscribeAllLoggedInDevices(Long rootUserId, String topic) { | ||
| userQueryPort.findByLoggedInUserId(rootUserId) | ||
| .forEach(user -> userEventPort.subscribeEvent(user.getFcmToken(), topic)); | ||
|
|
||
| log.info("동아리 토픽 구독 완료. rootUserId={}, topic={}", rootUserId, topic); | ||
| } | ||
|
|
||
| private void unsubscribeAllLoggedInDevices(Long rootUserId, String topic) { | ||
| userQueryPort.findByLoggedInUserId(rootUserId) | ||
| .forEach(user -> userEventPort.unsubscribeEvent(user.getFcmToken(), topic)); | ||
|
|
||
| log.info("동아리 토픽 구독 해제 완료. rootUserId={}, topic={}", rootUserId, topic); | ||
| } | ||
rlagkswn00 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private String makeTopic(Club club) { | ||
| return serverProperties.ifDevThenAddSuffix(CLUB_TOPIC_PREFIX + club.getId()); | ||
| } | ||
rlagkswn00 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
82 changes: 82 additions & 0 deletions
82
src/main/java/com/kustacks/kuring/club/application/service/ClubNotificationService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| package com.kustacks.kuring.club.application.service; | ||
|
|
||
| import com.google.firebase.messaging.Message; | ||
| import com.google.firebase.messaging.Notification; | ||
| import com.kustacks.kuring.club.application.port.in.ClubNotificationUseCase; | ||
| import com.kustacks.kuring.club.application.port.out.ClubQueryPort; | ||
| import com.kustacks.kuring.club.domain.Club; | ||
| import com.kustacks.kuring.common.annotation.UseCase; | ||
| import com.kustacks.kuring.common.properties.ServerProperties; | ||
| import com.kustacks.kuring.message.application.port.out.FirebaseMessagingPort; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import static com.kustacks.kuring.message.domain.MessageType.CLUB; | ||
|
|
||
| @Slf4j | ||
| @UseCase | ||
| @RequiredArgsConstructor | ||
| public class ClubNotificationService implements ClubNotificationUseCase { | ||
|
|
||
| private static final String CLUB_TOPIC_PREFIX = "club."; | ||
| private static final String D_DAY_1_TITLE = "[D-1] %s 동아리 모집"; | ||
| private static final String D_DAY_1_BODY = "내일 마감되기 전에 지원하세요!"; | ||
|
|
||
| private final ClubQueryPort clubQueryPort; | ||
| private final FirebaseMessagingPort firebaseMessagingPort; | ||
| private final ServerProperties serverProperties; | ||
|
|
||
| @Override | ||
| public void sendDeadlineNotifications() { | ||
| List<Club> clubs = findDeadlineClubs(); | ||
| clubs.forEach(this::sendDeadLineClubNotification); | ||
| } | ||
|
|
||
| private void sendDeadLineClubNotification(Club club) { | ||
| try { | ||
| Message message = buildMessage(club); | ||
| firebaseMessagingPort.send(message); | ||
| log.info("동아리 마감 알림 발송 완료. clubId={}", club.getId()); | ||
| } catch (Exception e) { | ||
| log.error("동아리 마감 알림 발송 실패. clubId={}", club.getId(), e); | ||
| } | ||
| } | ||
|
|
||
| private List<Club> findDeadlineClubs() { | ||
| return clubQueryPort.findNextDayRecruitEndClubs(LocalDateTime.now()); | ||
| } | ||
|
|
||
| private Message buildMessage(Club club) { | ||
| String messageTitle = String.format(D_DAY_1_TITLE, club.getName()); | ||
|
|
||
| return Message.builder() | ||
| .setNotification(buildNotification(messageTitle, D_DAY_1_BODY)) | ||
| .setTopic(buildTopic(club)) | ||
| .putAllData(buildMessageData(messageTitle, D_DAY_1_BODY, club)) | ||
| .build(); | ||
| } | ||
|
|
||
| private Map<String, String> buildMessageData(String title, String body, Club club) { | ||
| return Map.of( | ||
| "clubId", String.valueOf(club.getId()), | ||
| "title", title, | ||
| "body", body, | ||
| "messageType", CLUB.getValue() | ||
| ); | ||
| } | ||
|
|
||
| private String buildTopic(Club club) { | ||
| return serverProperties.ifDevThenAddSuffix(CLUB_TOPIC_PREFIX + club.getId()); | ||
| } | ||
rlagkswn00 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private Notification buildNotification(String title, String body) { | ||
| return Notification.builder() | ||
| .setTitle(title) | ||
| .setBody(body) | ||
| .build(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,4 +74,5 @@ public class Club { | |
|
|
||
| @Column(columnDefinition = "TEXT") | ||
| private String qualifications; | ||
|
|
||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fcm 구독 로직이 트랜잭션 내부에 있어서 subscribeAllLoggedInDevices 중간에 예외 발생하면 db만 롤백되고 이미 수행된 일부 fcm 구독은 롤백 안되는 문제가 생길수도 있을 것 같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
구독 Event가 TransactionalEventListner로 동작하고 있어서 트랜잭션 커밋 후에 이벤트가 진행하도록 되어있는걸로 확인했습니다! 그래서 DB가 롤백될 상황이라면 FCM구독도 이루어지지 않을거 같습니다!