From 78ec648f117fe28233dc7d5223603422f3fba1e4 Mon Sep 17 00:00:00 2001 From: kimyu0218 Date: Sun, 22 Dec 2024 15:45:39 +0900 Subject: [PATCH 1/4] =?UTF-8?q?fix:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EB=8B=B9=EC=8B=9C=20=EB=94=94=EB=B0=94=EC=9D=B4=EC=8A=A4=20?= =?UTF-8?q?=ED=86=A0=ED=81=B0=EC=9D=84=20=EC=97=85=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8=20=ED=95=98=EC=A7=80=20=EC=95=8A=EC=9D=80=20=EA=B2=BD?= =?UTF-8?q?=EC=9A=B0=20=EB=B6=84=EA=B8=B0=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/device/DeviceSubscriptionService.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/nexters/goalpanzi/application/device/DeviceSubscriptionService.java b/src/main/java/com/nexters/goalpanzi/application/device/DeviceSubscriptionService.java index 6f1fa9d..2b49831 100644 --- a/src/main/java/com/nexters/goalpanzi/application/device/DeviceSubscriptionService.java +++ b/src/main/java/com/nexters/goalpanzi/application/device/DeviceSubscriptionService.java @@ -95,7 +95,12 @@ private List findTopicSubscribers(final Long missionId) { */ @Transactional public void subscribeToMyMissions(final Long memberId, final String deviceIdentifier) { - Device device = deviceRepository.getDevice(memberId, deviceIdentifier); + Device device = deviceRepository.findByMemberIdAndDeviceIdentifier(memberId, deviceIdentifier) + .orElse(null); + if (device == null) { + return; + } + List topics = findMySubscribedTopics(device.getId()); List missions = missionRepository.findAllById( findMySubscribableMission(memberId, topics) From f81a8fcd9f381d3b26894d9c741229b37a869e65 Mon Sep 17 00:00:00 2001 From: kimyu0218 Date: Sun, 22 Dec 2024 15:46:39 +0900 Subject: [PATCH 2/4] =?UTF-8?q?move:=20=EB=94=94=EB=B0=94=EC=9D=B4?= =?UTF-8?q?=EC=8A=A4=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=B2=98=EB=A6=AC=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EB=94=94=EB=B0=94=EC=9D=B4=EC=8A=A4=20=EC=9D=B4?= =?UTF-8?q?=EB=B2=A4=ED=8A=B8=20=ED=95=B8=EB=93=A4=EB=9F=AC=EB=A1=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DeviceSubscriptionEventHandler.java | 17 ++++++++++++++++- .../handler/PushMessageEventHandler.java | 19 ------------------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/nexters/goalpanzi/application/device/event/handler/DeviceSubscriptionEventHandler.java b/src/main/java/com/nexters/goalpanzi/application/device/event/handler/DeviceSubscriptionEventHandler.java index 628e25c..ce6c451 100644 --- a/src/main/java/com/nexters/goalpanzi/application/device/event/handler/DeviceSubscriptionEventHandler.java +++ b/src/main/java/com/nexters/goalpanzi/application/device/event/handler/DeviceSubscriptionEventHandler.java @@ -4,6 +4,8 @@ import com.nexters.goalpanzi.application.device.DeviceSubscriptionService; import com.nexters.goalpanzi.application.device.event.UpdateDeviceTokenEvent; import com.nexters.goalpanzi.application.device.event.UpdatePushActivationStatusEvent; +import com.nexters.goalpanzi.application.mission.event.SubscribeToMissionEvent; +import com.nexters.goalpanzi.application.mission.event.UnsubscribeFromMissionEvent; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.Async; @@ -24,7 +26,7 @@ public class DeviceSubscriptionEventHandler { @Transactional(propagation = Propagation.REQUIRES_NEW) @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) void handleUpdateDeviceTokenEvent(final UpdateDeviceTokenEvent event) { - if (event.deprecatedDeviceToken() != null) { + if (event.isTokenDeprecated()) { deviceSubscriptionService.unsubscribeFromMyMissions(event.memberId(), event.deviceId(), event.deprecatedDeviceToken()); } deviceSubscriptionService.subscribeToMyMissions(event.memberId(), event.deviceId()); @@ -52,4 +54,17 @@ void handleLoginEvent(final LoginEvent event) { log.info("Handled LoginEvent for memberId: {}", event.memberId()); } + @Async + @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) + void handleSubscribeMissionEvent(final SubscribeToMissionEvent event) { + deviceSubscriptionService.subscribeToMission(event.memberId(), event.mission()); + log.info("Handled SubscribeMissionEvent for memberId: {} and missionId: {}", event.memberId(), event.mission().getId()); + } + + @Async + @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) + void handleUnsubscribeFromMissionEvent(final UnsubscribeFromMissionEvent event) { + deviceSubscriptionService.unsubscribeFromMission(event.missionId()); + log.info("Handled UnsubscribeMissionEvent from missionId: {}", event.missionId()); + } } diff --git a/src/main/java/com/nexters/goalpanzi/application/firebase/event/handler/PushMessageEventHandler.java b/src/main/java/com/nexters/goalpanzi/application/firebase/event/handler/PushMessageEventHandler.java index b26862c..a466b9b 100644 --- a/src/main/java/com/nexters/goalpanzi/application/firebase/event/handler/PushMessageEventHandler.java +++ b/src/main/java/com/nexters/goalpanzi/application/firebase/event/handler/PushMessageEventHandler.java @@ -1,11 +1,8 @@ package com.nexters.goalpanzi.application.firebase.event.handler; -import com.nexters.goalpanzi.application.device.DeviceSubscriptionService; import com.nexters.goalpanzi.application.firebase.TopicGenerator; import com.nexters.goalpanzi.application.mission.event.CompleteMissionEvent; import com.nexters.goalpanzi.application.mission.event.JoinMissionEvent; -import com.nexters.goalpanzi.application.mission.event.SubscribeToMissionEvent; -import com.nexters.goalpanzi.application.mission.event.UnsubscribeFromMissionEvent; import com.nexters.goalpanzi.infrastructure.firebase.PushMessageSender; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -25,8 +22,6 @@ @Component public class PushMessageEventHandler { - private final DeviceSubscriptionService deviceSubscriptionService; - private final PushMessageSender pushMessageSender; @Async @@ -59,18 +54,4 @@ void handleCompleteMissionEvent(final CompleteMissionEvent event) { ); log.info("Handled CompleteMissionEvent for missionId: {}", event.missionId()); } - - @Async - @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) - void handleSubscribeMissionEvent(final SubscribeToMissionEvent event) { - deviceSubscriptionService.subscribeToMission(event.memberId(), event.mission()); - log.info("Handled SubscribeMissionEvent for memberId: {} and missionId: {}", event.memberId(), event.mission().getId()); - } - - @Async - @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) - void handleUnsubscribeFromMissionEvent(final UnsubscribeFromMissionEvent event) { - deviceSubscriptionService.unsubscribeFromMission(event.missionId()); - log.info("Handled UnsubscribeMissionEvent from missionId: {}", event.missionId()); - } } From 491df5f9b8e169be0406f466058411787bef0707 Mon Sep 17 00:00:00 2001 From: kimyu0218 Date: Sun, 22 Dec 2024 15:47:27 +0900 Subject: [PATCH 3/4] =?UTF-8?q?refactor:=20=ED=86=A0=ED=81=B0=20=EB=A7=8C?= =?UTF-8?q?=EB=A3=8C=20=EC=97=AC=EB=B6=80=20=EC=B2=B4=ED=81=AC=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/device/event/UpdateDeviceTokenEvent.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/nexters/goalpanzi/application/device/event/UpdateDeviceTokenEvent.java b/src/main/java/com/nexters/goalpanzi/application/device/event/UpdateDeviceTokenEvent.java index 52a0e21..cd81cea 100644 --- a/src/main/java/com/nexters/goalpanzi/application/device/event/UpdateDeviceTokenEvent.java +++ b/src/main/java/com/nexters/goalpanzi/application/device/event/UpdateDeviceTokenEvent.java @@ -5,4 +5,8 @@ public record UpdateDeviceTokenEvent( Long deviceId, String deprecatedDeviceToken ) { + + public boolean isTokenDeprecated() { + return deprecatedDeviceToken != null; + } } From 3e342f91e7a1646f06190e40f8e07e8b6d003aea Mon Sep 17 00:00:00 2001 From: kimyu0218 Date: Sun, 22 Dec 2024 15:48:26 +0900 Subject: [PATCH 4/4] =?UTF-8?q?test:=20=EC=98=A4=EB=A5=98=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=EC=97=90=20=EB=94=B0=EB=A5=B8=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/device/DeviceSubscriptionServiceTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/nexters/goalpanzi/application/device/DeviceSubscriptionServiceTest.java b/src/test/java/com/nexters/goalpanzi/application/device/DeviceSubscriptionServiceTest.java index 4ce5255..203c3e7 100644 --- a/src/test/java/com/nexters/goalpanzi/application/device/DeviceSubscriptionServiceTest.java +++ b/src/test/java/com/nexters/goalpanzi/application/device/DeviceSubscriptionServiceTest.java @@ -20,6 +20,7 @@ import org.springframework.test.context.ContextConfiguration; import java.util.List; +import java.util.Optional; import static com.nexters.goalpanzi.domain.mission.MissionStatus.CREATED; import static com.nexters.goalpanzi.fixture.DeviceFixture.DEVICE_IDENTIFIER; @@ -132,7 +133,7 @@ void setUp() { DeviceSubscription mockDeviceSubscription = mock(DeviceSubscription.class); when(mockDeviceSubscription.getMission()).thenReturn(mockSubscribedMission); - when(deviceRepository.getDevice(MEMBER_ID, DEVICE_IDENTIFIER)).thenReturn(mockDevice); + when(deviceRepository.findByMemberIdAndDeviceIdentifier(MEMBER_ID, DEVICE_IDENTIFIER)).thenReturn(Optional.of(mockDevice)); when(deviceSubscriptionRepository.findAllWithMissionAndDeviceByDeviceId(DEVICE_ID)) .thenReturn(List.of(mockDeviceSubscription));