-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
517 additions
and
86 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
24 changes: 0 additions & 24 deletions
24
...in/com/depromeet/whatnow/domains/interaction/handler/InteractionHistoryRegisterHandler.kt
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
14 changes: 14 additions & 0 deletions
14
...src/main/kotlin/com/depromeet/whatnow/domains/notification/adapter/NotificationAdapter.kt
This file contains 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,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) | ||
} | ||
} |
This file contains 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
This file contains 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
6 changes: 6 additions & 0 deletions
6
...in/kotlin/com/depromeet/whatnow/domains/notification/repository/NotificationRepository.kt
This file contains 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.depromeet.whatnow.domains.notification.repository | ||
|
||
import com.depromeet.whatnow.domains.notification.domain.Notification | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
|
||
interface NotificationRepository : JpaRepository<Notification, Long> |
42 changes: 42 additions & 0 deletions
42
...in/kotlin/com/depromeet/whatnow/domains/notification/service/NotificationDomainService.kt
This file contains 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,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<Long>, promiseImageId: Long) { | ||
notificationAdapter.save(Notification.createForImage(userId, targetUserId, promiseImageId)) | ||
} | ||
|
||
@Transactional | ||
fun saveForStartSharing(targetUserIds: Set<Long>, promiseId: Long) { | ||
notificationAdapter.save(Notification.createForStartSharing(targetUserIds, promiseId)) | ||
} | ||
|
||
@Transactional | ||
fun saveForEndSharing(targetUserIds: Set<Long>, promiseId: Long) { | ||
notificationAdapter.save(Notification.createForEndSharing(targetUserIds, promiseId)) | ||
} | ||
|
||
@Transactional | ||
fun saveForTimeOver(targetUserIds: Set<Long>, 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<Long>, interactionType: InteractionType) { | ||
notificationAdapter.save(Notification.createForInteractionAttainment(userId, senderUserIds, interactionType)) | ||
} | ||
} |
This file contains 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
10 changes: 10 additions & 0 deletions
10
...-Domain/src/main/kotlin/com/depromeet/whatnow/events/domainEvent/InteractionFixedEvent.kt
This file contains 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.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() |
2 changes: 1 addition & 1 deletion
2
.../event/InteractionHistoryRegisterEvent.kt → ...nEvent/InteractionHistoryRegisterEvent.kt
This file contains 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
This file contains 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
58 changes: 55 additions & 3 deletions
58
...-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/ImageRegisterEventHandler.kt
This file contains 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 |
---|---|---|
@@ -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<String, String> = 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) | ||
} | ||
} |
Oops, something went wrong.