From a07eb925c04058186f51d43fdf242f764eceb77a Mon Sep 17 00:00:00 2001 From: BlackBean99 <54030889+BlackBean99@users.noreply.github.com> Date: Tue, 11 Jul 2023 21:13:19 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[DPMBE-114]=20=EC=95=BD=EC=86=8D=20?= =?UTF-8?q?=EC=A0=95=EB=A0=AC=20=EC=88=9C=EC=84=9C=EB=A5=BC=20=EC=98=A4?= =?UTF-8?q?=EB=9E=98=EB=90=9C=20=EC=88=9C=EC=9C=BC=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=ED=95=9C=EB=8B=A4=20(#184)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat : 예정된 약속 정렬 순서 변경 * refactor: spotless --- .../whatnow/api/promise/usecase/PromiseReadUseCase.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promise/usecase/PromiseReadUseCase.kt b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promise/usecase/PromiseReadUseCase.kt index 0c7659be..a9f21280 100644 --- a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promise/usecase/PromiseReadUseCase.kt +++ b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promise/usecase/PromiseReadUseCase.kt @@ -69,7 +69,13 @@ class PromiseReadUseCase( } val action: (Entry>) -> Unit = { (promiseType, promiseFindDtos) -> - promiseFindDtos.sortBy { it.endTime } + // promiseType == BEFORE 인 것만 정렬 + when (promiseType) { + // 예정된 약속은 오름차순 정렬 + PromiseType.BEFORE -> promiseFindDtos.sortBy { it.endTime } + // 종료된 약속은 내림차순 정렬 + else -> promiseFindDtos.sortByDescending { it.endTime } + } } promiseSplitByPromiseTypeDto.forEach(action) } @@ -119,7 +125,7 @@ class PromiseReadUseCase( } val promiseImagesUrls = promiseImageAdapter.findAllByPromiseId(promise.id!!) - .sortedByDescending { it.createdAt } + .sortedBy { it.createdAt } .map { it.uri } val timeOverLocations = promiseUsers.mapNotNull { promiseUser -> From 86591357d78dcbd34b49ba47b1e633fd2a39d750 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=8F=84=EB=AA=A8?= Date: Wed, 12 Jul 2023 00:20:18 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[DPMBE-101]=20=EC=95=8C=EB=A6=BC=EC=9D=B4?= =?UTF-8?q?=20=ED=95=84=EC=9A=94=ED=95=9C=20=EC=9D=B4=EB=B2=A4=ED=8A=B8?= =?UTF-8?q?=EC=9D=BC=EB=95=8C=20FCM=20=EB=A9=94=EC=84=B8=EC=A7=80=EB=A5=BC?= =?UTF-8?q?=20=EB=B0=9C=EC=86=A1=ED=95=9C=EB=8B=A4=20(#185)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * move: event와 handler 패키지 이동 * style: handler 메서드명 통일 * feat: 이미지를 올렸을때 FCM 발송 * feat: 위치 공유 시작할때 FCM 발송 * feat: TIMEOVER 되었을때 FCM 발송 * feat: Interaction 전송 시 FCM 발송 * feat: fcm message send할 때 data값 추가 * feat: 위치 공유 종료 시 FCM 발송 * feat: Interaction 100개 달성 시 FCM 발송 * Interaction 100개 달성 시 이벤트 발행 로직 handler로 이동 --- .../depromeet/whatnow/consts/WhatNowStatic.kt | 1 + .../domains/interaction/domain/Interaction.kt | 3 +- .../InteractionHistoryRegisterHandler.kt | 24 ------ .../service/InteractionDomainService.kt | 4 +- .../domain/InteractionHistory.kt | 2 +- .../adapter/NotificationAdapter.kt | 14 +++ .../notification/domain/Notification.kt | 86 +++++++++++++++++-- .../notification/domain/NotificationType.kt | 3 +- .../repository/NotificationRepository.kt | 6 ++ .../service/NotificationDomainService.kt | 42 +++++++++ .../whatnow/domains/user/domain/User.kt | 4 +- .../domainEvent/InteractionFixedEvent.kt | 10 +++ .../InteractionHistoryRegisterEvent.kt | 2 +- ...serSignUpEvent.kt => UserRegisterEvent.kt} | 2 +- .../handler/ImageRegisterEventHandler.kt | 58 ++++++++++++- .../handler/InteractionFixedEventHandler.kt | 56 ++++++++++++ .../InteractionHistoryRegisterHandler.kt | 60 +++++++++++++ .../handler/PromiseActivationEventHandler.kt | 2 +- .../handler/PromiseRegisterEventHandler.kt | 2 +- .../handler/PromiseTimeEndEventHandler.kt | 62 ++++++++++++- .../handler/PromiseTimeStartEventHandler.kt | 33 ++++++- .../PromiseTrackingTimeEndEventHandler.kt | 38 +++++++- .../PromiseUserRegisterEventHandler.kt | 6 -- ...omiseUserRegisterInteractionInitHandler.kt | 2 +- .../UserProfileImageUpdatedEventHandler.kt | 2 +- .../handler/UserRegisterEventHandler.kt | 17 ++++ .../events/handler/UserSignUpEventHandler.kt | 18 ---- ...ventTests.kt => UserRegisterEventTests.kt} | 8 +- .../PromiseImageRegisterEventHandlerTest.kt | 2 +- .../whatnow/config/fcm/FcmService.kt | 24 ++++-- 30 files changed, 509 insertions(+), 84 deletions(-) delete mode 100644 Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/interaction/handler/InteractionHistoryRegisterHandler.kt create mode 100644 Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/adapter/NotificationAdapter.kt create mode 100644 Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/repository/NotificationRepository.kt create mode 100644 Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/service/NotificationDomainService.kt create mode 100644 Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/domainEvent/InteractionFixedEvent.kt rename Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/{domains/interactionhistory/event => events/domainEvent}/InteractionHistoryRegisterEvent.kt (82%) rename Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/domainEvent/{UserSignUpEvent.kt => UserRegisterEvent.kt} (83%) create mode 100644 Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/InteractionFixedEventHandler.kt create mode 100644 Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/InteractionHistoryRegisterHandler.kt delete mode 100644 Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseUserRegisterEventHandler.kt rename Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/{domains/interaction => events}/handler/PromiseUserRegisterInteractionInitHandler.kt (94%) create mode 100644 Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/UserRegisterEventHandler.kt delete mode 100644 Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/UserSignUpEventHandler.kt rename Whatnow-Domain/src/test/kotlin/com/depromeet/whatnow/events/{UserSignUpEventTests.kt => UserRegisterEventTests.kt} (75%) diff --git a/Whatnow-Common/src/main/kotlin/com/depromeet/whatnow/consts/WhatNowStatic.kt b/Whatnow-Common/src/main/kotlin/com/depromeet/whatnow/consts/WhatNowStatic.kt index 041efe77..9c1058ae 100644 --- a/Whatnow-Common/src/main/kotlin/com/depromeet/whatnow/consts/WhatNowStatic.kt +++ b/Whatnow-Common/src/main/kotlin/com/depromeet/whatnow/consts/WhatNowStatic.kt @@ -26,6 +26,7 @@ const val DEV = "dev" const val LOCAL = "local" const val WITHDRAW_PREFIX = "withdraw" const val RADIUS_WAIT_CONFIRM = 200 +const val INTERACTION_FIXED_COUNT = 200L const val SLACK_MAX_LENGTH = 1000 const val NCP_LOCAL_SEARCH_DISPLAY_COUNT = 10 diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/interaction/domain/Interaction.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/interaction/domain/Interaction.kt index 92a82a04..e72571c0 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/interaction/domain/Interaction.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/interaction/domain/Interaction.kt @@ -27,8 +27,9 @@ class Interaction( @Column(name = "interaction_id") val id: Long? = null, ) : BaseTimeEntity() { - fun increment() { + fun increment(): Long { count += 1 + return count } companion object { diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/interaction/handler/InteractionHistoryRegisterHandler.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/interaction/handler/InteractionHistoryRegisterHandler.kt deleted file mode 100644 index 98e3c5e3..00000000 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/interaction/handler/InteractionHistoryRegisterHandler.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.depromeet.whatnow.domains.interaction.handler - -import com.depromeet.whatnow.annotation.Handler -import com.depromeet.whatnow.domains.interaction.service.InteractionDomainService -import com.depromeet.whatnow.domains.interactionhistory.event.InteractionHistoryRegisterEvent -import mu.KLogger -import mu.KotlinLogging -import org.springframework.scheduling.annotation.Async -import org.springframework.transaction.event.TransactionPhase -import org.springframework.transaction.event.TransactionalEventListener - -@Handler -class InteractionHistoryRegisterHandler( - val interactionDomainService: InteractionDomainService, -) { - val logger: KLogger = KotlinLogging.logger {} - - @Async - @TransactionalEventListener(classes = [InteractionHistoryRegisterEvent::class], phase = TransactionPhase.AFTER_COMMIT) - fun handleInteractionHistoryRegisterEvent(event: InteractionHistoryRegisterEvent) { - logger.info { "handleInteractionHistoryRegisterEvent 이벤트 약속아이디 {${event.promiseId} , 유저아이디: ${event.userId} , 상대방 유저아이디: ${event.targetUserId} , 인터렉션타입: ${event.interactionType}" } - interactionDomainService.increment(event.promiseId, event.userId, event.interactionType) - } -} diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/interaction/service/InteractionDomainService.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/interaction/service/InteractionDomainService.kt index 0d0ebbc4..2de8fac5 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/interaction/service/InteractionDomainService.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/interaction/service/InteractionDomainService.kt @@ -24,9 +24,9 @@ class InteractionDomainService( identifier = "userId", ) @CheckUserParticipation - fun increment(promiseId: Long, userId: Long, interactionType: InteractionType) { + fun increment(promiseId: Long, userId: Long, interactionType: InteractionType): Long { val interaction = interactionAdapter.queryInteraction(promiseId, userId, interactionType) - interaction.increment() + return interaction.increment() } @CheckUserParticipation diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/interactionhistory/domain/InteractionHistory.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/interactionhistory/domain/InteractionHistory.kt index d327e643..0814f0b9 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/interactionhistory/domain/InteractionHistory.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/interactionhistory/domain/InteractionHistory.kt @@ -3,7 +3,7 @@ package com.depromeet.whatnow.domains.interactionhistory.domain import com.depromeet.whatnow.common.BaseTimeEntity import com.depromeet.whatnow.common.aop.event.Events import com.depromeet.whatnow.domains.interaction.domain.InteractionType -import com.depromeet.whatnow.domains.interactionhistory.event.InteractionHistoryRegisterEvent +import com.depromeet.whatnow.events.domainEvent.InteractionHistoryRegisterEvent import javax.persistence.Column import javax.persistence.Entity import javax.persistence.GeneratedValue diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/adapter/NotificationAdapter.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/adapter/NotificationAdapter.kt new file mode 100644 index 00000000..c2e622d2 --- /dev/null +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/adapter/NotificationAdapter.kt @@ -0,0 +1,14 @@ +package com.depromeet.whatnow.domains.notification.adapter + +import com.depromeet.whatnow.annotation.Adapter +import com.depromeet.whatnow.domains.notification.domain.Notification +import com.depromeet.whatnow.domains.notification.repository.NotificationRepository + +@Adapter +class NotificationAdapter( + val notificationRepository: NotificationRepository, +) { + fun save(notification: Notification): Notification { + return notificationRepository.save(notification) + } +} diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/domain/Notification.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/domain/Notification.kt index 8d4e7df5..f5061040 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/domain/Notification.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/domain/Notification.kt @@ -2,6 +2,7 @@ package com.depromeet.whatnow.domains.notification.domain import com.depromeet.whatnow.common.BaseTimeEntity import com.depromeet.whatnow.domains.interaction.domain.InteractionType +import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUserType import javax.persistence.Column import javax.persistence.ElementCollection import javax.persistence.Entity @@ -19,17 +20,92 @@ class Notification( var notificationType: NotificationType, @Enumerated(EnumType.STRING) - var interactionType: InteractionType, + var interactionType: InteractionType?, - var userId: Long, + @Enumerated(EnumType.STRING) + var promiseUserType: PromiseUserType?, + + var userId: Long?, @ElementCollection - var targetUserId: Set, + var targetUserIds: Set, - var targetId: Long, + var targetId: Long?, @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "notification_id") val id: Long? = null, -) : BaseTimeEntity() +) : BaseTimeEntity() { + companion object { + fun createForImage(userId: Long, targetUserId: Set, promiseImageId: Long): Notification { + return Notification( + notificationType = NotificationType.IMAGE, + userId = userId, + targetUserIds = targetUserId, + targetId = promiseImageId, + interactionType = null, + promiseUserType = null, + ) + } + + fun createForStartSharing(targetUserIds: Set, promiseId: Long): Notification { + return Notification( + notificationType = NotificationType.START_SHARING, + userId = null, + targetUserIds = targetUserIds, + targetId = promiseId, + interactionType = null, + promiseUserType = null, + ) + } + + fun createForEndSharing(targetUserIds: Set, promiseId: Long): Notification { + return Notification( + notificationType = NotificationType.END_SHARING, + userId = null, + targetUserIds = targetUserIds, + targetId = promiseId, + interactionType = null, + promiseUserType = null, + ) + } + + fun createForTimeOver(targetUserIds: Set, promiseId: Long): Notification { + return Notification( + notificationType = NotificationType.TIMEOVER, + userId = null, + targetUserIds = targetUserIds, + targetId = promiseId, + interactionType = null, + promiseUserType = null, + ) + } + + fun createForInteraction(userId: Long, targetUserId: Long, interactionType: InteractionType): Notification { + return Notification( + notificationType = NotificationType.INTERACTION, + userId = userId, + targetUserIds = mutableSetOf(targetUserId), + targetId = null, + interactionType = interactionType, + promiseUserType = null, + ) + } + + fun createForInteractionAttainment( + userId: Long, + senderUserIds: Set, + interactionType: InteractionType, + ): Notification { + return Notification( + notificationType = NotificationType.INTERACTION_ATTAINMENT, + userId = userId, + targetUserIds = senderUserIds, + targetId = null, + interactionType = interactionType, + promiseUserType = null, + ) + } + } +} diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/domain/NotificationType.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/domain/NotificationType.kt index b354fd49..771a8032 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/domain/NotificationType.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/domain/NotificationType.kt @@ -5,7 +5,8 @@ enum class NotificationType(val kr: String) { ARRIVAL("도착"), TIMEOVER("시간 초과"), INTERACTION("인터렉션"), - PICTURE("사진"), + INTERACTION_ATTAINMENT("인터렉션 달성"), + IMAGE("이미지"), START_SHARING("공유 시작"), END_SHARING("공유 종료"), } diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/repository/NotificationRepository.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/repository/NotificationRepository.kt new file mode 100644 index 00000000..37427109 --- /dev/null +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/repository/NotificationRepository.kt @@ -0,0 +1,6 @@ +package com.depromeet.whatnow.domains.notification.repository + +import com.depromeet.whatnow.domains.notification.domain.Notification +import org.springframework.data.jpa.repository.JpaRepository + +interface NotificationRepository : JpaRepository diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/service/NotificationDomainService.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/service/NotificationDomainService.kt new file mode 100644 index 00000000..74995c81 --- /dev/null +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/notification/service/NotificationDomainService.kt @@ -0,0 +1,42 @@ +package com.depromeet.whatnow.domains.notification.service + +import com.depromeet.whatnow.domains.interaction.domain.InteractionType +import com.depromeet.whatnow.domains.notification.adapter.NotificationAdapter +import com.depromeet.whatnow.domains.notification.domain.Notification +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional + +@Service +class NotificationDomainService( + val notificationAdapter: NotificationAdapter, +) { + @Transactional + fun saveForImage(userId: Long, targetUserId: Set, promiseImageId: Long) { + notificationAdapter.save(Notification.createForImage(userId, targetUserId, promiseImageId)) + } + + @Transactional + fun saveForStartSharing(targetUserIds: Set, promiseId: Long) { + notificationAdapter.save(Notification.createForStartSharing(targetUserIds, promiseId)) + } + + @Transactional + fun saveForEndSharing(targetUserIds: Set, promiseId: Long) { + notificationAdapter.save(Notification.createForEndSharing(targetUserIds, promiseId)) + } + + @Transactional + fun saveForTimeOver(targetUserIds: Set, promiseId: Long) { + notificationAdapter.save(Notification.createForTimeOver(targetUserIds, promiseId)) + } + + @Transactional + fun saveForInteraction(userId: Long, targetUserId: Long, interactionType: InteractionType) { + notificationAdapter.save(Notification.createForInteraction(userId, targetUserId, interactionType)) + } + + @Transactional + fun saveForInteractionAttainment(userId: Long, senderUserIds: Set, interactionType: InteractionType) { + notificationAdapter.save(Notification.createForInteractionAttainment(userId, senderUserIds, interactionType)) + } +} diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/user/domain/User.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/user/domain/User.kt index bd0d510d..9d3c261c 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/user/domain/User.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/user/domain/User.kt @@ -8,7 +8,7 @@ import com.depromeet.whatnow.consts.USER_DEFAULT_PROFILE_IMAGE import com.depromeet.whatnow.domains.user.exception.AlreadyDeletedUserException import com.depromeet.whatnow.domains.user.exception.ForbiddenUserException import com.depromeet.whatnow.events.domainEvent.UserProfileImageUpdatedEvent -import com.depromeet.whatnow.events.domainEvent.UserSignUpEvent +import com.depromeet.whatnow.events.domainEvent.UserRegisterEvent import java.time.LocalDateTime import javax.persistence.Column import javax.persistence.Embedded @@ -52,7 +52,7 @@ class User( @PostPersist fun registerEvent() { - Events.raise(UserSignUpEvent(this.id!!)) + Events.raise(UserRegisterEvent(this.id!!)) } fun login(fcmToken: String) { diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/domainEvent/InteractionFixedEvent.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/domainEvent/InteractionFixedEvent.kt new file mode 100644 index 00000000..9482ccb7 --- /dev/null +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/domainEvent/InteractionFixedEvent.kt @@ -0,0 +1,10 @@ +package com.depromeet.whatnow.events.domainEvent + +import com.depromeet.whatnow.common.aop.event.DomainEvent +import com.depromeet.whatnow.domains.interaction.domain.InteractionType + +class InteractionFixedEvent( + val promiseId: Long, + val userId: Long, + val interactionType: InteractionType, +) : DomainEvent() diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/interactionhistory/event/InteractionHistoryRegisterEvent.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/domainEvent/InteractionHistoryRegisterEvent.kt similarity index 82% rename from Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/interactionhistory/event/InteractionHistoryRegisterEvent.kt rename to Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/domainEvent/InteractionHistoryRegisterEvent.kt index 21f29f67..c25f6cce 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/interactionhistory/event/InteractionHistoryRegisterEvent.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/domainEvent/InteractionHistoryRegisterEvent.kt @@ -1,4 +1,4 @@ -package com.depromeet.whatnow.domains.interactionhistory.event +package com.depromeet.whatnow.events.domainEvent import com.depromeet.whatnow.common.aop.event.DomainEvent import com.depromeet.whatnow.domains.interaction.domain.InteractionType diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/domainEvent/UserSignUpEvent.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/domainEvent/UserRegisterEvent.kt similarity index 83% rename from Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/domainEvent/UserSignUpEvent.kt rename to Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/domainEvent/UserRegisterEvent.kt index 8b6171f1..12f434cf 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/domainEvent/UserSignUpEvent.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/domainEvent/UserRegisterEvent.kt @@ -2,6 +2,6 @@ package com.depromeet.whatnow.events.domainEvent import com.depromeet.whatnow.common.aop.event.DomainEvent -data class UserSignUpEvent( +data class UserRegisterEvent( val userId: Long, ) : DomainEvent() diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/ImageRegisterEventHandler.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/ImageRegisterEventHandler.kt index a47bc846..b8e0ab37 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/ImageRegisterEventHandler.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/ImageRegisterEventHandler.kt @@ -1,18 +1,70 @@ package com.depromeet.whatnow.events.handler import com.depromeet.whatnow.annotation.Handler +import com.depromeet.whatnow.config.fcm.FcmService +import com.depromeet.whatnow.domains.notification.domain.NotificationType +import com.depromeet.whatnow.domains.notification.service.NotificationDomainService +import com.depromeet.whatnow.domains.promiseuser.adaptor.PromiseUserAdaptor +import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUserType.LATE +import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUserType.WAIT +import com.depromeet.whatnow.domains.user.adapter.UserAdapter import com.depromeet.whatnow.events.domainEvent.PromiseImageRegisterEvent import org.springframework.scheduling.annotation.Async import org.springframework.transaction.event.TransactionPhase import org.springframework.transaction.event.TransactionalEventListener @Handler -class ImageRegisterEventHandler { +class ImageRegisterEventHandler( + val promiseUserAdapter: PromiseUserAdaptor, + val userAdapter: UserAdapter, + val fcmService: FcmService, + val notificationDomainService: NotificationDomainService, +) { @Async @TransactionalEventListener(classes = [PromiseImageRegisterEvent::class], phase = TransactionPhase.AFTER_COMMIT) - fun handleRegisterPictureEvent(promiseImageRegisterEvent: PromiseImageRegisterEvent) { + fun handlePromiseImageRegisterEvent(promiseImageRegisterEvent: PromiseImageRegisterEvent) { val userId: Long = promiseImageRegisterEvent.userId val promiseId: Long = promiseImageRegisterEvent.promiseId - // TODO: FCM 토큰 발급 후 약속ID 기준 참여자들에게 푸시 알림 보내기 + + // 사진을 보낸 유저가 Late인지 Wait인지 확인하기 위한 PromiseUser 조회 + val promiseUser = promiseUserAdapter.findByPromiseIdAndUserId(promiseId, userId) + + // 약속에 참여한 유저들 조회 (사진 보낸 유저 제외) + val usersExcludingSelf = promiseUserAdapter.findByPromiseId(promiseId) + .filter { promiseUser -> promiseUser.userId != userId } + .map { promiseUser -> userAdapter.queryUser(promiseUser.userId) } + + // 앱 알람 허용한 유저 + val appAlarmPermitUsers = usersExcludingSelf.filter { user -> + user.fcmNotification.fcmToken != null && user.fcmNotification.appAlarm + } + + val data: MutableMap = mutableMapOf() + data["notificationType"] = NotificationType.IMAGE.name + data["promiseId"] = promiseId.toString() + + // 앱 알람 허용한 유저에게 알람 보내기 + when (promiseUser.promiseUserType) { + LATE -> { + fcmService.sendGroupMessageAsync( + appAlarmPermitUsers.map { user -> user.fcmNotification.fcmToken!! }, + "지각한 친구의 사진 도착", + "지각한 친구가 보낸 사진을 확인해봐!", + data, + ) + } + WAIT -> { + fcmService.sendGroupMessageAsync( + appAlarmPermitUsers.map { user -> user.fcmNotification.fcmToken!! }, + "도착한 친구들의 사진 도착", + "도착한 친구들이 보낸 사진을 확인해봐!", + data, + ) + } + } + + // notification 저장 + val targetUserIds = usersExcludingSelf.map { user -> user.id!! }.toSet() + notificationDomainService.saveForImage(userId, targetUserIds, promiseId) } } diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/InteractionFixedEventHandler.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/InteractionFixedEventHandler.kt new file mode 100644 index 00000000..6d912fcb --- /dev/null +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/InteractionFixedEventHandler.kt @@ -0,0 +1,56 @@ +package com.depromeet.whatnow.events.handler + +import com.depromeet.whatnow.annotation.Handler +import com.depromeet.whatnow.config.fcm.FcmService +import com.depromeet.whatnow.domains.interactionhistory.service.InteractionHistoryDomainService +import com.depromeet.whatnow.domains.notification.domain.NotificationType +import com.depromeet.whatnow.domains.notification.service.NotificationDomainService +import com.depromeet.whatnow.domains.user.adapter.UserAdapter +import com.depromeet.whatnow.events.domainEvent.InteractionFixedEvent +import mu.KLogger +import mu.KotlinLogging +import org.springframework.scheduling.annotation.Async +import org.springframework.transaction.event.TransactionPhase +import org.springframework.transaction.event.TransactionalEventListener + +@Handler +class InteractionFixedEventHandler( + val userAdapter: UserAdapter, + val fcmService: FcmService, + val notificationDomainService: NotificationDomainService, + val interactionHistoryDomainService: InteractionHistoryDomainService, +) { + val logger: KLogger = KotlinLogging.logger {} + + @Async + @TransactionalEventListener(classes = [InteractionFixedEvent::class], phase = TransactionPhase.AFTER_COMMIT) + fun handleInteractionFixedEvent(event: InteractionFixedEvent) { + val promiseId = event.promiseId + val userId = event.userId + val interactionType = event.interactionType + logger.info { "InteractionFixedEvent 이벤트 수신 promiseId=$promiseId, userId=$userId, interactionType=${interactionType.name}" } + + val user = userAdapter.queryUser(userId) + + val senderUserIds = + interactionHistoryDomainService.queryAllByInteractionType(userId, promiseId, interactionType) + .map { interactionHistory -> interactionHistory.targetUserId } + .distinct() + .toSet() + + val data: MutableMap = mutableMapOf() + data["notificationType"] = NotificationType.INTERACTION_ATTAINMENT.name + data["promiseId"] = event.promiseId.toString() + + if (user.fcmNotification.appAlarm) { + fcmService.sendMessageAsync( + user.fcmNotification.fcmToken, + "이모지 100개 달성!", + "", + data, + ) + } + + notificationDomainService.saveForInteractionAttainment(userId, senderUserIds, interactionType) + } +} diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/InteractionHistoryRegisterHandler.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/InteractionHistoryRegisterHandler.kt new file mode 100644 index 00000000..4c653980 --- /dev/null +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/InteractionHistoryRegisterHandler.kt @@ -0,0 +1,60 @@ +package com.depromeet.whatnow.events.handler + +import com.depromeet.whatnow.annotation.Handler +import com.depromeet.whatnow.common.aop.event.Events +import com.depromeet.whatnow.config.fcm.FcmService +import com.depromeet.whatnow.consts.INTERACTION_FIXED_COUNT +import com.depromeet.whatnow.domains.interaction.service.InteractionDomainService +import com.depromeet.whatnow.domains.notification.domain.NotificationType +import com.depromeet.whatnow.domains.notification.service.NotificationDomainService +import com.depromeet.whatnow.domains.user.adapter.UserAdapter +import com.depromeet.whatnow.events.domainEvent.InteractionFixedEvent +import com.depromeet.whatnow.events.domainEvent.InteractionHistoryRegisterEvent +import mu.KLogger +import mu.KotlinLogging +import org.springframework.scheduling.annotation.Async +import org.springframework.transaction.annotation.Propagation +import org.springframework.transaction.annotation.Transactional +import org.springframework.transaction.event.TransactionPhase +import org.springframework.transaction.event.TransactionalEventListener + +@Handler +class InteractionHistoryRegisterHandler( + val interactionDomainService: InteractionDomainService, + val userAdapter: UserAdapter, + val fcmService: FcmService, + val notificationDomainService: NotificationDomainService, +) { + val logger: KLogger = KotlinLogging.logger {} + + @Async + @Transactional(propagation = Propagation.REQUIRES_NEW) + @TransactionalEventListener(classes = [InteractionHistoryRegisterEvent::class], phase = TransactionPhase.AFTER_COMMIT) + fun handleInteractionHistoryRegisterEvent(event: InteractionHistoryRegisterEvent) { + logger.info { "handleInteractionHistoryRegisterEvent 이벤트 약속아이디 {${event.promiseId} , 유저아이디: ${event.userId} , 상대방 유저아이디: ${event.targetUserId} , 인터렉션타입: ${event.interactionType}" } + val interactionCount = interactionDomainService.increment(event.promiseId, event.userId, event.interactionType) + + if (interactionCount == INTERACTION_FIXED_COUNT) { + Events.raise(InteractionFixedEvent(event.promiseId, event.userId, event.interactionType)) + } + + val targetUser = userAdapter.queryUser(event.targetUserId) + if (!targetUser.fcmNotification.appAlarm) { + return + } + + val user = userAdapter.queryUser(event.userId) + + val data: MutableMap = mutableMapOf() + data["notificationType"] = NotificationType.INTERACTION.name + + fcmService.sendMessageAsync( + targetUser.fcmNotification.fcmToken, + "이모지 투척!", + "from. $user.nickname", + data, + ) + + notificationDomainService.saveForInteraction(user.id!!, targetUser.id!!, event.interactionType) + } +} diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseActivationEventHandler.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseActivationEventHandler.kt index 37ecf485..00f0162c 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseActivationEventHandler.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseActivationEventHandler.kt @@ -18,7 +18,7 @@ class PromiseActivationEventHandler( ) { @Async @TransactionalEventListener(classes = [PromiseRegisterEvent::class], phase = TransactionPhase.AFTER_COMMIT) - fun handleRegisterPictureEvent(promiseRegisterEvent: PromiseRegisterEvent) { + fun handlePromiseRegisterEvent(promiseRegisterEvent: PromiseRegisterEvent) { val promise = promiseDomainService.findByPromiseId(promiseRegisterEvent.promiseId) val now = LocalDateTime.now() diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseRegisterEventHandler.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseRegisterEventHandler.kt index 91d3abae..8e7e56f6 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseRegisterEventHandler.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseRegisterEventHandler.kt @@ -15,7 +15,7 @@ class PromiseRegisterEventHandler( ) { @Async @TransactionalEventListener(classes = [PromiseRegisterEvent::class], phase = TransactionPhase.AFTER_COMMIT) - fun handleRegisterPictureEvent(promiseRegisterEvent: PromiseRegisterEvent) { + fun handlePromiseRegisterEvent(promiseRegisterEvent: PromiseRegisterEvent) { // 약속 등록 시 방장의 PromiseUser 생성하기 val promiseUser = PromiseUser( promiseId = promiseRegisterEvent.promiseId, diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseTimeEndEventHandler.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseTimeEndEventHandler.kt index deee5851..e718581b 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseTimeEndEventHandler.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseTimeEndEventHandler.kt @@ -1,8 +1,14 @@ package com.depromeet.whatnow.events.handler +import com.depromeet.whatnow.config.fcm.FcmService +import com.depromeet.whatnow.domains.notification.domain.NotificationType +import com.depromeet.whatnow.domains.notification.service.NotificationDomainService import com.depromeet.whatnow.domains.promise.adaptor.PromiseAdaptor import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUserType.CANCEL +import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUserType.LATE +import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUserType.WAIT import com.depromeet.whatnow.domains.promiseuser.service.PromiseUserDomainService +import com.depromeet.whatnow.domains.user.adapter.UserAdapter import com.depromeet.whatnow.events.domainEvent.MeetPromiseUserEvent import com.depromeet.whatnow.events.domainEvent.PromiseTimeEndEvent import org.springframework.scheduling.annotation.Async @@ -16,11 +22,14 @@ import org.springframework.transaction.event.TransactionalEventListener class PromiseTimeEndEventHandler( val promiseAdaptor: PromiseAdaptor, val promiseUserDomainService: PromiseUserDomainService, + val userAdapter: UserAdapter, + val fcmService: FcmService, + val notificationDomainService: NotificationDomainService, ) { @Async @Transactional(propagation = REQUIRES_NEW) @TransactionalEventListener(classes = [PromiseTimeEndEvent::class], phase = TransactionPhase.AFTER_COMMIT) - fun handleRegisterUserEvent(endTimePromiseEvent: PromiseTimeEndEvent) { + fun handlePromiseTimeEndEvent(endTimePromiseEvent: PromiseTimeEndEvent) { val promiseId: Long = endTimePromiseEvent.promiseId val promise = promiseAdaptor.queryPromise(promiseId) val coordinate = promise.meetPlace?.coordinate @@ -39,6 +48,57 @@ class PromiseTimeEndEventHandler( } } } + + // 약속에 참여한 유저들 조회 + val users = promiseUsers + .map { promiseUser -> userAdapter.queryUser(promiseUser.userId) } + + // 앱 알람 허용한 유저 + val appAlarmPermitUsers = users + .filter { user -> user.fcmNotification.fcmToken != null && user.fcmNotification.appAlarm } + + val lateData: MutableMap = mutableMapOf() + lateData["notificationType"] = NotificationType.TIMEOVER.name + lateData["promiseId"] = promiseId.toString() + + // LATE 유저들에게 알림 발송 + val appAlarmPermitLateUserTokens = appAlarmPermitUsers + .filter { user -> + promiseUserDomainService.findByPromiseIdAndUserId( + promiseId, + user.id!!, + ).promiseUserType == LATE + } + .map { user -> user.fcmNotification.fcmToken } + fcmService.sendGroupMessageAsync( + appAlarmPermitLateUserTokens, + "TIMEOVER!", + "친구들에게 용서를 비는 사진을 보내봐!", + lateData, + ) + + val waitData: MutableMap = mutableMapOf() + waitData["notificationType"] = NotificationType.TIMEOVER.name + waitData["promiseId"] = promiseId.toString() + + val appAlarmPermitWaitUserTokens = appAlarmPermitUsers + .filter { user -> + promiseUserDomainService.findByPromiseIdAndUserId( + promiseId, + user.id!!, + ).promiseUserType == WAIT + } + .map { user -> user.fcmNotification.fcmToken } + fcmService.sendGroupMessageAsync( + appAlarmPermitWaitUserTokens, + "TIMEOVER!", + "친구들에게 재촉하는 사진을 보내봐!", + waitData, + ) + + // notification 저장 + val targetUserIds = users.map { user -> user.id!! }.toSet() + notificationDomainService.saveForTimeOver(targetUserIds, promiseId) } @Async diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseTimeStartEventHandler.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseTimeStartEventHandler.kt index 34120ac2..f11a5072 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseTimeStartEventHandler.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseTimeStartEventHandler.kt @@ -1,6 +1,10 @@ package com.depromeet.whatnow.events.handler +import com.depromeet.whatnow.config.fcm.FcmService +import com.depromeet.whatnow.domains.notification.domain.NotificationType +import com.depromeet.whatnow.domains.notification.service.NotificationDomainService import com.depromeet.whatnow.domains.promiseuser.adaptor.PromiseUserAdaptor +import com.depromeet.whatnow.domains.user.adapter.UserAdapter import com.depromeet.whatnow.events.domainEvent.PromiseTimeStartEvent import org.springframework.scheduling.annotation.Async import org.springframework.stereotype.Component @@ -11,11 +15,14 @@ import org.springframework.transaction.event.TransactionalEventListener @Component class PromiseTimeStartEventHandler( val promiseUserAdaptor: PromiseUserAdaptor, + val userAdapter: UserAdapter, + val fcmService: FcmService, + val notificationDomainService: NotificationDomainService, ) { @Async @Transactional @TransactionalEventListener(classes = [PromiseTimeStartEvent::class], phase = TransactionPhase.AFTER_COMMIT) - fun handleRegisterUserEvent(promiseTimeStartEvent: PromiseTimeStartEvent) { + fun handlePromiseTimeStartEvent(promiseTimeStartEvent: PromiseTimeStartEvent) { val promiseId = promiseTimeStartEvent.promiseId val promiseUsers = promiseUserAdaptor.findByPromiseId(promiseId) @@ -23,5 +30,29 @@ class PromiseTimeStartEventHandler( promiseUser.updatePromiseUserTypeToWait() promiseUser.userLocationInit() } + + // 약속에 참여한 유저들 조회 + val users = promiseUsers + .map { promiseUser -> userAdapter.queryUser(promiseUser.userId) } + + // 앱 알람 허용한 유저 + val appAlarmPermitUsers = users + .filter { user -> user.fcmNotification.fcmToken != null && user.fcmNotification.appAlarm } + + val data: MutableMap = mutableMapOf() + data["notificationType"] = NotificationType.START_SHARING.name + data["promiseId"] = promiseId.toString() + + // 앱 알람 허용한 유저에게 알람 보내기 + fcmService.sendGroupMessageAsync( + appAlarmPermitUsers.map { user -> user.fcmNotification.fcmToken!! }, + "위치 공유 시작!", + "공유 시작! 지도를 확인해봐!", + data, + ) + + // notification 저장 + val targetUserIds = users.map { user -> user.id!! }.toSet() + notificationDomainService.saveForStartSharing(targetUserIds, promiseId) } } diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseTrackingTimeEndEventHandler.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseTrackingTimeEndEventHandler.kt index 568bbfdd..e43e62dd 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseTrackingTimeEndEventHandler.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseTrackingTimeEndEventHandler.kt @@ -1,10 +1,15 @@ package com.depromeet.whatnow.events.handler +import com.depromeet.whatnow.config.fcm.FcmService +import com.depromeet.whatnow.domains.notification.domain.NotificationType +import com.depromeet.whatnow.domains.notification.service.NotificationDomainService import com.depromeet.whatnow.domains.promise.adaptor.PromiseAdaptor import com.depromeet.whatnow.domains.promiseuser.adaptor.PromiseUserAdaptor +import com.depromeet.whatnow.domains.user.adapter.UserAdapter import com.depromeet.whatnow.events.domainEvent.PromiseTrackingTimeEndEvent import org.springframework.scheduling.annotation.Async import org.springframework.stereotype.Component +import org.springframework.transaction.annotation.Propagation import org.springframework.transaction.annotation.Transactional import org.springframework.transaction.event.TransactionPhase import org.springframework.transaction.event.TransactionalEventListener @@ -13,13 +18,42 @@ import org.springframework.transaction.event.TransactionalEventListener class PromiseTrackingTimeEndEventHandler( val promiseAdaptor: PromiseAdaptor, val promiseUserAdaptor: PromiseUserAdaptor, + val userAdapter: UserAdapter, + val fcmService: FcmService, + val notificationDomainService: NotificationDomainService, ) { @Async - @Transactional + @Transactional(propagation = Propagation.REQUIRES_NEW) @TransactionalEventListener(classes = [PromiseTrackingTimeEndEvent::class], phase = TransactionPhase.AFTER_COMMIT) - fun handleRegisterUserEvent(promiseTrackingTimeEndEvent: PromiseTrackingTimeEndEvent) { + fun handlePromiseTrackingTimeEndEvent(promiseTrackingTimeEndEvent: PromiseTrackingTimeEndEvent) { val promiseId = promiseTrackingTimeEndEvent.promiseId val promise = promiseAdaptor.queryPromise(promiseId) promise.endPromise() + + val promiseUsers = promiseUserAdaptor.findByPromiseId(promiseId) + + // 약속에 참여한 유저들 조회 + val users = promiseUsers + .map { promiseUser -> userAdapter.queryUser(promiseUser.userId) } + + // 앱 알람 허용한 유저 + val appAlarmPermitUsers = users + .filter { user -> user.fcmNotification.fcmToken != null && user.fcmNotification.appAlarm } + + val data: MutableMap = mutableMapOf() + data["notificationType"] = NotificationType.END_SHARING.name + data["promiseId"] = promiseId.toString() + + // 앱 알람 허용한 유저에게 알람 보내기 + fcmService.sendGroupMessageAsync( + appAlarmPermitUsers.map { user -> user.fcmNotification.fcmToken!! }, + "위치 공유 종료!", + "어떤 일이 있었는지 돌아보자!", + data, + ) + + // notification 저장 + val targetUserIds = users.map { user -> user.id!! }.toSet() + notificationDomainService.saveForEndSharing(targetUserIds, promiseId) } } diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseUserRegisterEventHandler.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseUserRegisterEventHandler.kt deleted file mode 100644 index 83a4ae95..00000000 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseUserRegisterEventHandler.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.depromeet.whatnow.events.handler - -import org.springframework.stereotype.Component - -@Component -class PromiseUserRegisterEventHandler() diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/interaction/handler/PromiseUserRegisterInteractionInitHandler.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseUserRegisterInteractionInitHandler.kt similarity index 94% rename from Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/interaction/handler/PromiseUserRegisterInteractionInitHandler.kt rename to Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseUserRegisterInteractionInitHandler.kt index 935cd44c..1aae8e3d 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/interaction/handler/PromiseUserRegisterInteractionInitHandler.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseUserRegisterInteractionInitHandler.kt @@ -1,4 +1,4 @@ -package com.depromeet.whatnow.domains.interaction.handler +package com.depromeet.whatnow.events.handler import com.depromeet.whatnow.annotation.Handler import com.depromeet.whatnow.domains.interaction.service.InteractionDomainService diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/UserProfileImageUpdatedEventHandler.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/UserProfileImageUpdatedEventHandler.kt index 9b4903fc..ff4ff4ef 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/UserProfileImageUpdatedEventHandler.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/UserProfileImageUpdatedEventHandler.kt @@ -15,7 +15,7 @@ class UserProfileImageUpdatedEventHandler( ) { @Async @TransactionalEventListener(classes = [UserProfileImageUpdatedEvent::class], phase = TransactionPhase.AFTER_COMMIT) - fun handleRegisterUserEvent(userProfileImageUpdatedEvent: UserProfileImageUpdatedEvent) { + fun handleUpdateUserProfileImageEvent(userProfileImageUpdatedEvent: UserProfileImageUpdatedEvent) { val userId = userProfileImageUpdatedEvent.userId val imageKey = userProfileImageUpdatedEvent.imageKey diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/UserRegisterEventHandler.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/UserRegisterEventHandler.kt new file mode 100644 index 00000000..7b8722f2 --- /dev/null +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/UserRegisterEventHandler.kt @@ -0,0 +1,17 @@ +package com.depromeet.whatnow.events.handler + +import com.depromeet.whatnow.events.domainEvent.UserRegisterEvent +import org.springframework.scheduling.annotation.Async +import org.springframework.stereotype.Component +import org.springframework.transaction.event.TransactionPhase +import org.springframework.transaction.event.TransactionalEventListener + +@Component +class UserRegisterEventHandler { + + @Async + @TransactionalEventListener(classes = [UserRegisterEvent::class], phase = TransactionPhase.AFTER_COMMIT) + fun handleUserRegisterEvent(userRegisterEvent: UserRegisterEvent) { + val userId: Long = userRegisterEvent.userId + } +} diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/UserSignUpEventHandler.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/UserSignUpEventHandler.kt deleted file mode 100644 index bfe9d10d..00000000 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/UserSignUpEventHandler.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.depromeet.whatnow.events.handler - -import com.depromeet.whatnow.events.domainEvent.UserSignUpEvent -import org.springframework.scheduling.annotation.Async -import org.springframework.stereotype.Component -import org.springframework.transaction.event.TransactionPhase -import org.springframework.transaction.event.TransactionalEventListener - -@Component -class UserSignUpEventHandler { - - @Async - @TransactionalEventListener(classes = [UserSignUpEvent::class], phase = TransactionPhase.AFTER_COMMIT) - fun handleRegisterUserEvent(userSignUpEvent: UserSignUpEvent) { - val userId: Long = userSignUpEvent.userId - println(userId) - } -} diff --git a/Whatnow-Domain/src/test/kotlin/com/depromeet/whatnow/events/UserSignUpEventTests.kt b/Whatnow-Domain/src/test/kotlin/com/depromeet/whatnow/events/UserRegisterEventTests.kt similarity index 75% rename from Whatnow-Domain/src/test/kotlin/com/depromeet/whatnow/events/UserSignUpEventTests.kt rename to Whatnow-Domain/src/test/kotlin/com/depromeet/whatnow/events/UserRegisterEventTests.kt index c9aeb2df..d479f873 100644 --- a/Whatnow-Domain/src/test/kotlin/com/depromeet/whatnow/events/UserSignUpEventTests.kt +++ b/Whatnow-Domain/src/test/kotlin/com/depromeet/whatnow/events/UserRegisterEventTests.kt @@ -4,7 +4,7 @@ import com.depromeet.whatnow.config.DomainIntegrateSpringBootTest import com.depromeet.whatnow.domains.user.domain.OauthInfo import com.depromeet.whatnow.domains.user.domain.OauthProvider import com.depromeet.whatnow.domains.user.service.UserDomainService -import com.depromeet.whatnow.events.handler.UserSignUpEventHandler +import com.depromeet.whatnow.events.handler.UserRegisterEventHandler import org.junit.jupiter.api.Test import org.mockito.Mockito import org.mockito.kotlin.any @@ -13,17 +13,17 @@ import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.mock.mockito.MockBean @DomainIntegrateSpringBootTest -class UserSignUpEventTests { +class UserRegisterEventTests { @Autowired lateinit var userDomainService: UserDomainService - @MockBean lateinit var userSignUpEventHandler: UserSignUpEventHandler + @MockBean lateinit var userRegisterEventHandler: UserRegisterEventHandler @Test fun `유저회원가입시 유저등록 이벤트가 발행되어야한다`() { // when userDomainService.upsertUser("", "", true, OauthInfo("", OauthProvider.KAKAO), "") // then - then(userSignUpEventHandler).should(Mockito.times(1)).handleRegisterUserEvent(any()) + then(userRegisterEventHandler).should(Mockito.times(1)).handleUserRegisterEvent(any()) } } diff --git a/Whatnow-Domain/src/test/kotlin/com/depromeet/whatnow/events/handler/PromiseImageRegisterEventHandlerTest.kt b/Whatnow-Domain/src/test/kotlin/com/depromeet/whatnow/events/handler/PromiseImageRegisterEventHandlerTest.kt index 48882d6b..60639cc5 100644 --- a/Whatnow-Domain/src/test/kotlin/com/depromeet/whatnow/events/handler/PromiseImageRegisterEventHandlerTest.kt +++ b/Whatnow-Domain/src/test/kotlin/com/depromeet/whatnow/events/handler/PromiseImageRegisterEventHandlerTest.kt @@ -41,6 +41,6 @@ class PromiseImageRegisterEventHandlerTest { imageDomainService.promiseImageUploadSuccess(1, 1, "imageKey", ImageFileExtension.JPEG, PromiseImageCommentType.RUNNING) // then - then(imageRegisterEventHandler).should(Mockito.times(1)).handleRegisterPictureEvent(any()) + then(imageRegisterEventHandler).should(Mockito.times(1)).handlePromiseImageRegisterEvent(any()) } } diff --git a/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/config/fcm/FcmService.kt b/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/config/fcm/FcmService.kt index 048fc518..803f0a3b 100644 --- a/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/config/fcm/FcmService.kt +++ b/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/config/fcm/FcmService.kt @@ -14,7 +14,7 @@ class FcmService { tokenList: List, title: String, content: String, - imageUrl: String, + data: MutableMap, ): ApiFuture { val multicast = MulticastMessage.builder() .addAllTokens(tokenList) @@ -22,17 +22,29 @@ class FcmService { Notification.builder() .setTitle(title) .setBody(content) - .setImage(imageUrl) .build(), - ).build() + ) + .putAllData(data) + .build() return FirebaseMessaging.getInstance().sendMulticastAsync(multicast) } - fun sendMessageSync(token: String, content: String) { + fun sendMessageAsync( + token: String, + title: String, + content: String, + data: MutableMap, + ): ApiFuture { val message = Message.builder() .setToken(token) - .setNotification(Notification.builder().setBody(content).build()) + .setNotification( + Notification.builder() + .setTitle(title) + .setBody(content) + .build(), + ) + .putAllData(data) .build() - FirebaseMessaging.getInstance().send(message) + return FirebaseMessaging.getInstance().sendAsync(message) } }