-
Notifications
You must be signed in to change notification settings - Fork 7
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
채팅 알림 메시지 형식 수정 #651
Merged
Merged
채팅 알림 메시지 형식 수정 #651
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c9baf2c
feat: 알림 예외 메시지 및 커스텀 예외 추가
pricelees f7d804d
refactor: 알림 이벤트 객체 생성시 채팅 / 채팅이 아닌 경우를 구분하기 위한 팩토리 메서드 추가
pricelees d0c9439
feat: 채팅 알림시 날짜 / 시간을 '~월 ~일 ~시 ~분' 형식으로 보내기 위한 유틸 클래스 추가
pricelees 16fdc6f
refactor: 알림 메시지 생성 역할 변경에 따른 NotificationType의 메시지 제거
pricelees 66b4e61
refactor: 변경된 사항을 채팅 서비스에 반영
pricelees f16653f
Merge branch 'develop-backend' into refactor/#642
pricelees 98395e0
refactor: 채팅 서비스에서의 타입에 따른 처리 수정
pricelees 749ebdb
refactor: 채팅 알림에서 새로 추가된 베팅 기능 지원
pricelees 80341ee
Merge branch 'develop-backend' into refactor/#642
pricelees 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
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,16 +4,24 @@ | |||||
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||||||
import org.springframework.context.ApplicationEventPublisher; | ||||||
import org.springframework.http.HttpStatus; | ||||||
import org.springframework.stereotype.Component; | ||||||
|
||||||
import lombok.RequiredArgsConstructor; | ||||||
import mouda.backend.bet.domain.Bet; | ||||||
import mouda.backend.bet.implement.BetFinder; | ||||||
import mouda.backend.chat.domain.ChatRoom; | ||||||
import mouda.backend.chat.domain.ChatRoomType; | ||||||
import mouda.backend.common.config.UrlConfig; | ||||||
import mouda.backend.darakbangmember.domain.DarakbangMember; | ||||||
import mouda.backend.moim.domain.Moim; | ||||||
import mouda.backend.moim.implement.finder.ChatRecipientFinder; | ||||||
import mouda.backend.moim.implement.finder.MoimFinder; | ||||||
import mouda.backend.notification.domain.NotificationEvent; | ||||||
import mouda.backend.notification.domain.NotificationType; | ||||||
import mouda.backend.notification.domain.Recipient; | ||||||
import mouda.backend.notification.exception.NotificationErrorMessage; | ||||||
import mouda.backend.notification.exception.NotificationException; | ||||||
|
||||||
@Component | ||||||
@EnableConfigurationProperties(UrlConfig.class) | ||||||
|
@@ -23,23 +31,78 @@ public class ChatNotificationSender { | |||||
private final UrlConfig urlConfig; | ||||||
private final ChatRecipientFinder chatRecipientFinder; | ||||||
private final ApplicationEventPublisher eventPublisher; | ||||||
private final MoimFinder moimFinder; | ||||||
private final BetFinder betFinder; | ||||||
|
||||||
public void sendChatNotification(Moim moim, DarakbangMember sender, NotificationType notificationType, long chatRoomId) { | ||||||
List<Recipient> recipients = chatRecipientFinder.getChatNotificationRecipients(moim.getId(), sender); | ||||||
NotificationEvent notificationEvent = createNotificationEvent(moim, sender, notificationType, recipients, chatRoomId); | ||||||
public void sendChatNotification( | ||||||
long darakbangId, ChatRoom chatRoom, String content, DarakbangMember sender, NotificationType notificationType | ||||||
) { | ||||||
ChatRoomType chatRoomType = chatRoom.getType(); | ||||||
long chatRoomId = chatRoom.getId(); | ||||||
if (chatRoomType == ChatRoomType.BET) { | ||||||
Bet bet = betFinder.find(darakbangId, chatRoom.getTargetId()); | ||||||
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. read로 바꾸면 좋을 것 같아용 |
||||||
sendBetNotification(bet, content, sender, notificationType); | ||||||
return; | ||||||
} | ||||||
Moim moim = moimFinder.read(chatRoom.getTargetId(), darakbangId); | ||||||
sendMoimNotification(moim, content, sender, notificationType, chatRoomId); | ||||||
} | ||||||
|
||||||
private void sendBetNotification( | ||||||
Bet bet, String content, DarakbangMember sender, NotificationType notificationType | ||||||
) { | ||||||
List<Recipient> recipients = chatRecipientFinder.getBetChatNotificationRecipients(bet.getId(), sender); | ||||||
long darakbangId = bet.getDarakbangId(); | ||||||
long chatRoomId = bet.getId(); | ||||||
|
||||||
publishEvent(notificationType, bet.getTitle(), content, sender, recipients, darakbangId, chatRoomId); | ||||||
} | ||||||
|
||||||
private void sendMoimNotification( | ||||||
Moim moim, String content, DarakbangMember sender, NotificationType notificationType, long chatRoomId | ||||||
) { | ||||||
List<Recipient> recipients = chatRecipientFinder.getMoimChatNotificationRecipients(moim.getId(), sender); | ||||||
long darakbangId = moim.getDarakbangId(); | ||||||
|
||||||
publishEvent(notificationType, moim.getTitle(), content, sender, recipients, darakbangId, chatRoomId); | ||||||
} | ||||||
|
||||||
private void publishEvent( | ||||||
NotificationType notificationType, String title, String content, DarakbangMember sender, | ||||||
List<Recipient> recipients, long darakbangId, long chatRoomId | ||||||
) { | ||||||
NotificationEvent notificationEvent = NotificationEvent.chatEvent( | ||||||
notificationType, | ||||||
title, | ||||||
ChatNotificationMessage.create(content, sender, notificationType), | ||||||
urlConfig.getChatRoomUrl(darakbangId, chatRoomId), | ||||||
recipients, | ||||||
darakbangId, | ||||||
chatRoomId | ||||||
); | ||||||
|
||||||
eventPublisher.publishEvent(notificationEvent); | ||||||
} | ||||||
|
||||||
private NotificationEvent createNotificationEvent(Moim moim, DarakbangMember sender, NotificationType notificationType, List<Recipient> recipients, long chatRoomId) { | ||||||
String message; | ||||||
if (notificationType.isConfirmedType()) { | ||||||
message = notificationType.createMessage(moim.getTitle()); | ||||||
} else { | ||||||
message = notificationType.createMessage(sender.getNickname()); | ||||||
static class ChatNotificationMessage { | ||||||
|
||||||
public static String create(String content, DarakbangMember sender, NotificationType type) { | ||||||
if (type.isConfirmedType()) { | ||||||
return confirmedChatMessage(content, type); | ||||||
} | ||||||
if (type == NotificationType.NEW_CHAT) { | ||||||
return sender.getNickname() + ": " + content; | ||||||
} | ||||||
throw new NotificationException( | ||||||
HttpStatus.BAD_REQUEST, NotificationErrorMessage.NOT_ALLOWED_NOTIFICATION_TYPE | ||||||
); | ||||||
} | ||||||
|
||||||
return new NotificationEvent( | ||||||
notificationType, moim.getTitle(), message, urlConfig.getChatRoomUrl(moim.getDarakbangId(), chatRoomId), recipients, moim.getDarakbangId(), chatRoomId); | ||||||
private static String confirmedChatMessage(String content, NotificationType type) { | ||||||
if (type == NotificationType.MOIM_PLACE_CONFIRMED) { | ||||||
return "장소가 '" + content + "' 로 확정되었어요!"; | ||||||
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.
Suggested change
|
||||||
} | ||||||
return "시간이 '" + content + "' 로 확정되었어요!"; | ||||||
} | ||||||
} | ||||||
} |
14 changes: 14 additions & 0 deletions
14
backend/src/main/java/mouda/backend/chat/util/DateTimeFormatter.java
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 mouda.backend.chat.util; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalTime; | ||
|
||
public class DateTimeFormatter { | ||
|
||
public static String formatDateTime(LocalDate date, LocalTime time) { | ||
return date.getMonth().getValue() + "월 " | ||
+ date.getDayOfMonth() + "일 " | ||
+ time.getHour() + "시 " | ||
+ time.getMinute() + "분"; | ||
} | ||
} |
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
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
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.
DarakbangMember이 알림을 받는 사람일까요? 그렇다면
receiver
가 맞을 것 같습니다 😀