-
Notifications
You must be signed in to change notification settings - Fork 3
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
[BE] refactor: 알림 서비스 다른 도메인 의존성 제거 #740
base: develop
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.happy.friendogly.notification.service; | ||
|
||
import static com.happy.friendogly.notification.domain.NotificationType.CHAT; | ||
|
||
import com.happy.friendogly.chatsocket.dto.response.ChatMessageSocketResponse; | ||
import com.happy.friendogly.club.domain.Club; | ||
import com.happy.friendogly.notification.repository.DeviceTokenRepository; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class ChatNotificationService { | ||
|
||
private final DeviceTokenRepository deviceTokenRepository; | ||
private final NotificationService notificationService; | ||
|
||
public ChatNotificationService( | ||
DeviceTokenRepository deviceTokenRepository, | ||
NotificationService notificationService | ||
) { | ||
this.deviceTokenRepository = deviceTokenRepository; | ||
this.notificationService = notificationService; | ||
} | ||
|
||
public void sendChatNotification(Long chatRoomId, ChatMessageSocketResponse response, Club club) { | ||
List<String> receiverTokens = deviceTokenRepository | ||
.findAllByChatRoomIdWithoutMine(chatRoomId, response.senderMemberId()); | ||
|
||
Map<String, String> data = Map.of( | ||
"chatRoomId", chatRoomId.toString(), | ||
"messageType", response.messageType().toString(), | ||
"senderMemberId", response.senderMemberId().toString(), | ||
"senderName", response.senderName(), | ||
"content", response.content(), | ||
"createdAt", response.createdAt().toString(), | ||
"profilePictureUrl", response.profilePictureUrl() == null ? "" : response.profilePictureUrl(), | ||
"clubPictureUrl", club.getImageUrl() == null ? "" : club.getImageUrl(), | ||
"clubTitle", club.getTitle().getValue() | ||
); | ||
|
||
notificationService.sendNotification("채팅", data, CHAT, receiverTokens); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package com.happy.friendogly.notification.service; | ||
|
||
import static com.happy.friendogly.notification.domain.NotificationType.FOOTPRINT; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. static import는 제거하는게 어떨까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 동의합니다 |
||
import com.happy.friendogly.footprint.domain.Footprint; | ||
import com.happy.friendogly.footprint.domain.WalkStatus; | ||
import com.happy.friendogly.notification.domain.DeviceToken; | ||
|
@@ -35,28 +37,31 @@ public void sendWalkNotificationToMe(Long memberId, WalkStatus currentWalkStatus | |
return; | ||
} | ||
|
||
notificationService.sendFootprintNotification( | ||
notificationService.sendNotification( | ||
DEFAULT_TITLE, | ||
content, | ||
deviceTokenRepository.getByMemberId(memberId).getDeviceToken() | ||
FOOTPRINT, | ||
List.of(deviceTokenRepository.getByMemberId(memberId).getDeviceToken()) | ||
); | ||
} | ||
|
||
public void sendWalkComingNotification(String comingMemberName, List<Footprint> nearFootprints) { | ||
List<String> nearDeviceTokens = toDeviceToken(nearFootprints); | ||
|
||
notificationService.sendFootprintNotification( | ||
notificationService.sendNotification( | ||
DEFAULT_TITLE, | ||
"내 산책 장소에 " + comingMemberName + "님도 산책온대요!", | ||
FOOTPRINT, | ||
nearDeviceTokens | ||
); | ||
} | ||
|
||
public void sendWalkStartNotificationToNear(String startMemberName, List<Footprint> nearFootprints) { | ||
List<String> nearDeviceTokens = toDeviceToken(nearFootprints); | ||
|
||
notificationService.sendFootprintNotification(DEFAULT_TITLE, | ||
notificationService.sendNotification(DEFAULT_TITLE, | ||
"내 산책장소에 " + startMemberName + "님이 산책을 시작했어요!", | ||
FOOTPRINT, | ||
nearDeviceTokens | ||
); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,22 @@ | ||
package com.happy.friendogly.notification.service; | ||
|
||
import com.happy.friendogly.chatsocket.dto.response.ChatMessageSocketResponse; | ||
import com.happy.friendogly.club.domain.Club; | ||
import com.happy.friendogly.notification.domain.NotificationType; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public interface NotificationService { | ||
|
||
void sendFootprintNotification(String title, String content, String receiverToken); | ||
void sendNotification( | ||
String title, | ||
String content, | ||
NotificationType notificationType, | ||
List<String> receiverTokens | ||
); | ||
|
||
void sendFootprintNotification(String title, String content, List<String> receiverTokens); | ||
|
||
void sendChatNotification(Long chatRoomId, ChatMessageSocketResponse response, Club club); | ||
|
||
void sendPlaygroundJoinNotification(String title, String content, List<String> receiverTokens); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오오 추상 메서드가 많이 줄어들었네요 |
||
void sendNotification( | ||
String title, | ||
Map<String, String> contents, | ||
NotificationType notificationType, | ||
List<String> receiverTokens | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package com.happy.friendogly.notification.service; | ||
|
||
import static com.happy.friendogly.notification.domain.NotificationType.PLAYGROUND; | ||
|
||
import com.happy.friendogly.notification.domain.DeviceToken; | ||
import com.happy.friendogly.notification.repository.DeviceTokenRepository; | ||
import com.happy.friendogly.playground.domain.PlaygroundMember; | ||
|
@@ -15,19 +17,25 @@ public class PlaygroundNotificationService { | |
private final DeviceTokenRepository deviceTokenRepository; | ||
private final NotificationService notificationService; | ||
|
||
public PlaygroundNotificationService(DeviceTokenRepository deviceTokenRepository, | ||
NotificationService notificationService) { | ||
public PlaygroundNotificationService( | ||
DeviceTokenRepository deviceTokenRepository, | ||
NotificationService notificationService | ||
) { | ||
this.deviceTokenRepository = deviceTokenRepository; | ||
this.notificationService = notificationService; | ||
} | ||
|
||
public void sendJoinNotification(String newParticipatingMember, | ||
List<PlaygroundMember> existingParticipatingMembers) { | ||
public void sendJoinNotification( | ||
String newParticipatingMember, | ||
List<PlaygroundMember> existingParticipatingMembers | ||
) { | ||
List<String> deviceTokens = toDeviceToken(existingParticipatingMembers); | ||
String content = newParticipatingMember + "님이 놀이터에 참여했습니다"; | ||
|
||
notificationService.sendPlaygroundJoinNotification(DEFAULT_TITLE, | ||
notificationService.sendNotification( | ||
DEFAULT_TITLE, | ||
Comment on lines
+34
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 예전에 작성된 코드같긴 한데 |
||
content, | ||
PLAYGROUND, | ||
deviceTokens | ||
); | ||
} | ||
|
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.
아하 이런 문제가 있었군요 !!!
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.
테스트가 터져서 확인해보니 해당부분 문제가 보이더라구요~!