Skip to content
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

채팅 알림 버그픽스 #687

Merged
merged 12 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ public void reopenMoim(Long darakbangId, Long moimId, DarakbangMember darakbangM

public void editMoim(Long darakbangId, MoimEditRequest request, DarakbangMember darakbangMember) {
Moim moim = moimFinder.read(request.moimId(), darakbangId);
String oldTitle = moim.getTitle();
moimWriter.updateMoim(moim, darakbangMember, request.title(), request.date(), request.time(), request.place(),
request.maxPeople(), request.description());

moimNotificationSender.sendMoimStatusChangedNotification(moim, NotificationType.MOIM_MODIFIED);
moimNotificationSender.sendMoimInfoModifiedNotification(moim, oldTitle, NotificationType.MOIM_MODIFIED);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public List<Recipient> getMoimCreatedNotificationRecipients(long darakbangId, lo
.toList();
}

public List<Recipient> getMoimStatusChangedNotificationRecipients(long moimId) {
public List<Recipient> getMoimModifiedNotificationRecipients(long moimId) {
List<Chamyo> chamyos = chamyoRepository.findAllByMoimId(moimId);

return chamyos.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import mouda.backend.common.config.UrlConfig;
import mouda.backend.darakbang.domain.Darakbang;
import mouda.backend.darakbang.exception.DarakbangErrorMessage;
import mouda.backend.darakbang.exception.DarakbangException;
import mouda.backend.darakbang.infrastructure.DarakbangRepository;
import mouda.backend.darakbangmember.domain.DarakbangMember;
import mouda.backend.moim.domain.Moim;
Expand Down Expand Up @@ -36,50 +38,58 @@ public MoimNotificationSender(UrlConfig urlConfig, ApplicationEventPublisher eve
public void sendMoimCreatedNotification(Moim moim, DarakbangMember author, NotificationType notificationType) {
List<Recipient> recipients = moimRecipientFinder.getMoimCreatedNotificationRecipients(moim.getDarakbangId(),
author.getId());
Darakbang darakbang = darakbangRepository.findById(moim.getDarakbangId())
.orElseThrow(IllegalArgumentException::new);
NotificationEvent notificationEvent = NotificationEvent.nonChatEvent(
notificationType,
darakbang.getName(),
MoimNotificationMessage.create(moim.getTitle(), notificationType),
getMoimUrl(darakbang.getId(), moim.getId()),
recipients
);
eventPublisher.publishEvent(notificationEvent);
String message = MoimNotificationMessage.create(moim.getTitle(), notificationType);

createEventAndPublish(notificationType, moim, message, recipients);
}

public void sendMoimStatusChangedNotification(Moim moim, NotificationType notificationType) {
List<Recipient> recipients = moimRecipientFinder.getMoimStatusChangedNotificationRecipients(moim.getId());
String message = MoimNotificationMessage.create(moim.getTitle(), notificationType);
sendMoimModifiedNotification(moim, notificationType, message);
}

public void sendMoimInfoModifiedNotification(Moim moim, String oldTitle, NotificationType notificationType) {
String message = MoimNotificationMessage.create(oldTitle, notificationType);
sendMoimModifiedNotification(moim, notificationType, message);
}

private void sendMoimModifiedNotification(Moim moim, NotificationType notificationType, String message) {
List<Recipient> recipients = moimRecipientFinder.getMoimModifiedNotificationRecipients(moim.getId());
createEventAndPublish(notificationType, moim, message, recipients);
}

private void createEventAndPublish(NotificationType notificationType, Moim moim, String message,
List<Recipient> recipients) {
Darakbang darakbang = darakbangRepository.findById(moim.getDarakbangId())
.orElseThrow(IllegalArgumentException::new);
.orElseThrow(() -> new DarakbangException(HttpStatus.NOT_FOUND, DarakbangErrorMessage.DARAKBANG_NOT_FOUND));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

package에 해당하는 예외를 던져주기로 했던 것 같아요

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

package에 해당하는 예외를 던져주기로 했던 것 같아요

해당 이유로 알림 타입에 대한 예외는 모임 에러를 사용했는데, 여기서는 좀 애매한 감이 있어서 다락방 예외를 사용했어요 ㅋㅋ 말씀주신대로 모임예외로 수정하고, 예외 메시지를 "모임에 해당되는 다락방을 찾을 수 없음" 으로 수정할게요 ~


NotificationEvent notificationEvent = NotificationEvent.nonChatEvent(
notificationType,
darakbang.getName(),
MoimNotificationMessage.create(moim.getTitle(), notificationType),
getMoimUrl(darakbang.getId(), moim.getId()),
message,
getMoimUrl(darakbang.getId(), darakbang.getId()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

두개 다 다락방 아이디 맞나여??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

두개 다 다락방 아이디 맞나여??

아뇨 ㅋㅋ 감사용 ㅋㅋ

recipients
);

eventPublisher.publishEvent(notificationEvent);
}

static class MoimNotificationMessage {

public static String create(String moimName, NotificationType type) {
public static String create(String moimTitle, NotificationType type) {
if (type == NotificationType.MOIM_CREATED) {
return moimName + " 모임이 만들어졌어요!";
return moimTitle + " 모임이 만들어졌어요!";
}
if (type == NotificationType.MOIMING_COMPLETED) {
return moimName + " 모집이 마감되었어요!";
return moimTitle + " 모집이 마감되었어요!";
}
if (type == NotificationType.MOINING_REOPENED) {
return moimName + " 모집이 재개되었어요!";
return moimTitle + " 모집이 재개되었어요!";
}
if (type == NotificationType.MOIM_CANCELLED) {
return moimName + " 모임이 취소되었어요!";
return moimTitle + " 모임이 취소되었어요!";
}
if (type == NotificationType.MOIM_MODIFIED) {
return moimName + " 모임 정보가 변경되었어요!";
return moimTitle + " 모임 정보가 변경되었어요!";
}
throw new NotificationException(
HttpStatus.BAD_REQUEST, NotificationErrorMessage.NOT_ALLOWED_NOTIFICATION_TYPE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void getMoimCreatedNotificationRecipients() {

@DisplayName("모임 상태 변화(모집마감, 모집재개, 모임정보변경, 모임장소/시간 확정)는 방장 제외 모임참여자 전원에게 알린다.")
@Test
void getMoimStatusChangedNotificationRecipients() {
void getMoimModifiedNotificationRecipients() {
// given
Moim moim = MoimFixture.getCoffeeMoim(darakbang.getId());
Moim savedMoim = moimRepository.save(moim);
Expand All @@ -64,7 +64,7 @@ void getMoimStatusChangedNotificationRecipients() {
chamyoRepository.save(chamyoWithMoimeeHogee);

// when
List<Recipient> recipients = moimRecipientFinder.getMoimStatusChangedNotificationRecipients(savedMoim.getId());
List<Recipient> recipients = moimRecipientFinder.getMoimModifiedNotificationRecipients(savedMoim.getId());

//then
assertThat(recipients).hasSize(1);
Expand Down