From b955c5c5408e63448dfd01d1436b2e45dc369370 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Sun, 8 Dec 2024 03:50:14 +0900 Subject: [PATCH 01/12] =?UTF-8?q?refactor(VolunteerApplyStatusChangeEvent)?= =?UTF-8?q?:=20=ED=8C=A8=ED=82=A4=EC=A7=80=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{domain => event}/VolunteerApplyStatusChangeEvent.java | 3 ++- .../volunteerapply/service/ApproveVolunteerApplyService.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) rename src/main/java/com/somemore/volunteerapply/{domain => event}/VolunteerApplyStatusChangeEvent.java (94%) diff --git a/src/main/java/com/somemore/volunteerapply/domain/VolunteerApplyStatusChangeEvent.java b/src/main/java/com/somemore/volunteerapply/event/VolunteerApplyStatusChangeEvent.java similarity index 94% rename from src/main/java/com/somemore/volunteerapply/domain/VolunteerApplyStatusChangeEvent.java rename to src/main/java/com/somemore/volunteerapply/event/VolunteerApplyStatusChangeEvent.java index 034121192..c1cff3689 100644 --- a/src/main/java/com/somemore/volunteerapply/domain/VolunteerApplyStatusChangeEvent.java +++ b/src/main/java/com/somemore/volunteerapply/event/VolunteerApplyStatusChangeEvent.java @@ -1,10 +1,11 @@ -package com.somemore.volunteerapply.domain; +package com.somemore.volunteerapply.event; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.somemore.global.common.event.ServerEvent; import com.somemore.global.common.event.ServerEventType; import com.somemore.notification.domain.NotificationSubType; +import com.somemore.volunteerapply.domain.ApplyStatus; import lombok.Getter; import lombok.experimental.SuperBuilder; diff --git a/src/main/java/com/somemore/volunteerapply/service/ApproveVolunteerApplyService.java b/src/main/java/com/somemore/volunteerapply/service/ApproveVolunteerApplyService.java index 8994a58c7..74d97b8c3 100644 --- a/src/main/java/com/somemore/volunteerapply/service/ApproveVolunteerApplyService.java +++ b/src/main/java/com/somemore/volunteerapply/service/ApproveVolunteerApplyService.java @@ -7,7 +7,7 @@ import com.somemore.recruitboard.domain.RecruitBoard; import com.somemore.recruitboard.usecase.query.RecruitBoardQueryUseCase; import com.somemore.volunteerapply.domain.VolunteerApply; -import com.somemore.volunteerapply.domain.VolunteerApplyStatusChangeEvent; +import com.somemore.volunteerapply.event.VolunteerApplyStatusChangeEvent; import com.somemore.volunteerapply.repository.VolunteerApplyRepository; import com.somemore.volunteerapply.usecase.ApproveVolunteerApplyUseCase; import lombok.RequiredArgsConstructor; From f387c80f2298076e5b512de5fdf788323eda3900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Sun, 8 Dec 2024 18:36:55 +0900 Subject: [PATCH 02/12] =?UTF-8?q?refactor(VolunteerApplyStatusChangeEvent)?= =?UTF-8?q?:=20=EC=9D=B8=EC=9E=90,=20=ED=8C=8C=EB=9D=BC=EB=AF=B8=ED=84=B0?= =?UTF-8?q?=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - oldStatus 추가. - 이벤트에 receiverId가 포함되는 것이 어색, volunteerId로 수정. --- .../event/VolunteerApplyStatusChangeEvent.java | 6 +++--- .../service/ApproveVolunteerApplyService.java | 11 +++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/somemore/volunteerapply/event/VolunteerApplyStatusChangeEvent.java b/src/main/java/com/somemore/volunteerapply/event/VolunteerApplyStatusChangeEvent.java index c1cff3689..ca8896958 100644 --- a/src/main/java/com/somemore/volunteerapply/event/VolunteerApplyStatusChangeEvent.java +++ b/src/main/java/com/somemore/volunteerapply/event/VolunteerApplyStatusChangeEvent.java @@ -16,7 +16,7 @@ @SuperBuilder public class VolunteerApplyStatusChangeEvent extends ServerEvent { - private final UUID receiverId; + private final UUID volunteerId; private final Long volunteerApplyId; private final UUID centerId; private final Long recruitBoardId; @@ -25,7 +25,7 @@ public class VolunteerApplyStatusChangeEvent extends ServerEvent Date: Sun, 8 Dec 2024 19:09:43 +0900 Subject: [PATCH 03/12] =?UTF-8?q?feat(VolunteerReviewRequestEvent):=20?= =?UTF-8?q?=EB=B4=89=EC=82=AC=20=ED=9B=84=EA=B8=B0=20=EC=9A=94=EC=B2=AD=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/VolunteerReviewRequestEvent.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/main/java/com/somemore/facade/event/VolunteerReviewRequestEvent.java diff --git a/src/main/java/com/somemore/facade/event/VolunteerReviewRequestEvent.java b/src/main/java/com/somemore/facade/event/VolunteerReviewRequestEvent.java new file mode 100644 index 000000000..ef19f4711 --- /dev/null +++ b/src/main/java/com/somemore/facade/event/VolunteerReviewRequestEvent.java @@ -0,0 +1,35 @@ +package com.somemore.facade.event; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.somemore.global.common.event.ServerEvent; +import com.somemore.global.common.event.ServerEventType; +import com.somemore.notification.domain.NotificationSubType; +import lombok.Getter; +import lombok.experimental.SuperBuilder; + +import java.time.LocalDateTime; +import java.util.UUID; + +@Getter +@SuperBuilder +public class VolunteerReviewRequestEvent extends ServerEvent { + private final UUID volunteerId; + private final Long volunteerApplyId; + private final UUID centerId; + private final Long recruitBoardId; + + @JsonCreator + public VolunteerReviewRequestEvent( + @JsonProperty("receiverId") UUID volunteerId, + @JsonProperty("volunteerApplyId") Long volunteerApplyId, + @JsonProperty("centerId") UUID centerId, + @JsonProperty("recruitBoardId") Long recruitBoardId + ) { + super(ServerEventType.NOTIFICATION, NotificationSubType.VOLUNTEER_APPLY_STATUS_CHANGE, LocalDateTime.now()); + this.volunteerId = volunteerId; + this.volunteerApplyId = volunteerApplyId; + this.centerId = centerId; + this.recruitBoardId = recruitBoardId; + } +} From 50e0229525540336dad3642845e8b4f071b2c2a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Sun, 8 Dec 2024 19:10:50 +0900 Subject: [PATCH 04/12] =?UTF-8?q?feat(VolunteerReviewRequestEvent):=20?= =?UTF-8?q?=EB=B4=89=EC=82=AC=20=ED=9B=84=EA=B8=B0=20=EC=9A=94=EC=B2=AD=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EB=B0=9C=ED=96=89=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - SettleVolunteerApplyFacadeService 에서 이벤트 발생. - subType 명명 수정. --- .../SettleVolunteerApplyFacadeService.java | 19 +++++++++++++++++++ .../domain/NotificationSubType.java | 2 +- .../NotificationCommandServiceTest.java | 2 +- .../service/NotificationQueryServiceTest.java | 2 +- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/somemore/facade/volunteerapply/SettleVolunteerApplyFacadeService.java b/src/main/java/com/somemore/facade/volunteerapply/SettleVolunteerApplyFacadeService.java index f2c25749f..d6cfb6d4e 100644 --- a/src/main/java/com/somemore/facade/volunteerapply/SettleVolunteerApplyFacadeService.java +++ b/src/main/java/com/somemore/facade/volunteerapply/SettleVolunteerApplyFacadeService.java @@ -4,7 +4,11 @@ import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_RECRUIT_BOARD; import static com.somemore.global.exception.ExceptionMessage.VOLUNTEER_APPLY_LIST_MISMATCH; +import com.somemore.facade.event.VolunteerReviewRequestEvent; +import com.somemore.global.common.event.ServerEventPublisher; +import com.somemore.global.common.event.ServerEventType; import com.somemore.global.exception.BadRequestException; +import com.somemore.notification.domain.NotificationSubType; import com.somemore.recruitboard.domain.RecruitBoard; import com.somemore.recruitboard.usecase.query.RecruitBoardQueryUseCase; import com.somemore.volunteer.usecase.UpdateVolunteerUseCase; @@ -25,6 +29,7 @@ public class SettleVolunteerApplyFacadeService implements SettleVolunteerApplyFa private final VolunteerApplyQueryUseCase volunteerApplyQueryUseCase; private final RecruitBoardQueryUseCase recruitBoardQueryUseCase; private final UpdateVolunteerUseCase updateVolunteerUseCase; + private final ServerEventPublisher serverEventPublisher; @Override public void settleVolunteerApplies(VolunteerApplySettleRequestDto dto, UUID centerId) { @@ -41,6 +46,7 @@ public void settleVolunteerApplies(VolunteerApplySettleRequestDto dto, UUID cent applies.forEach(apply -> { apply.changeAttended(true); updateVolunteerUseCase.updateVolunteerStats(apply.getVolunteerId(), hours); + publishVolunteerReviewRequestEvent(apply, recruitBoard); }); } @@ -68,4 +74,17 @@ private void validateRecruitBoardConsistency(List applies, throw new BadRequestException(RECRUIT_BOARD_ID_MISMATCH); } } + + private void publishVolunteerReviewRequestEvent(VolunteerApply apply, RecruitBoard recruitBoard) { + VolunteerReviewRequestEvent event = VolunteerReviewRequestEvent.builder() + .type(ServerEventType.NOTIFICATION) + .subType(NotificationSubType.VOLUNTEER_REVIEW_REQUEST) + .volunteerId(apply.getVolunteerId()) + .volunteerApplyId(apply.getId()) + .centerId(recruitBoard.getCenterId()) + .recruitBoardId(recruitBoard.getId()) + .build(); + + serverEventPublisher.publish(event); + } } diff --git a/src/main/java/com/somemore/notification/domain/NotificationSubType.java b/src/main/java/com/somemore/notification/domain/NotificationSubType.java index ad0eb05d8..1313069d8 100644 --- a/src/main/java/com/somemore/notification/domain/NotificationSubType.java +++ b/src/main/java/com/somemore/notification/domain/NotificationSubType.java @@ -7,7 +7,7 @@ @RequiredArgsConstructor public enum NotificationSubType { NOTE_BLAH_BLAH("쪽지"), - REVIEW_BLAH_BLAH("후기 요청"), + VOLUNTEER_REVIEW_REQUEST("봉사 후기 요청"), VOLUNTEER_APPLY_STATUS_CHANGE("신청 상태 변경") ; diff --git a/src/test/java/com/somemore/notification/service/NotificationCommandServiceTest.java b/src/test/java/com/somemore/notification/service/NotificationCommandServiceTest.java index 30231934e..1a5cf832b 100644 --- a/src/test/java/com/somemore/notification/service/NotificationCommandServiceTest.java +++ b/src/test/java/com/somemore/notification/service/NotificationCommandServiceTest.java @@ -126,7 +126,7 @@ private Notification createNotification(UUID receiverId) { return Notification.builder() .receiverId(receiverId) .title("Unread") - .type(NotificationSubType.REVIEW_BLAH_BLAH) + .type(NotificationSubType.VOLUNTEER_REVIEW_REQUEST) .relatedId(1L) .build(); } diff --git a/src/test/java/com/somemore/notification/service/NotificationQueryServiceTest.java b/src/test/java/com/somemore/notification/service/NotificationQueryServiceTest.java index 5ac0b661f..2b3522599 100644 --- a/src/test/java/com/somemore/notification/service/NotificationQueryServiceTest.java +++ b/src/test/java/com/somemore/notification/service/NotificationQueryServiceTest.java @@ -55,7 +55,7 @@ void getReadNotifications() { Notification readNotification = Notification.builder() .title("Read Notification") - .type(NotificationSubType.REVIEW_BLAH_BLAH) + .type(NotificationSubType.VOLUNTEER_REVIEW_REQUEST) .receiverId(receiverId) .relatedId(2L) .build(); From 3152a4475df2b9efea439b30f524d81cf08c263c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Sun, 8 Dec 2024 19:12:40 +0900 Subject: [PATCH 05/12] =?UTF-8?q?feat(NotificationHandlerImpl):=20?= =?UTF-8?q?=ED=8A=B8=EB=9E=9C=EC=9E=AD=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - DB save 작업 --- .../somemore/notification/handler/NotificationHandlerImpl.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/somemore/notification/handler/NotificationHandlerImpl.java b/src/main/java/com/somemore/notification/handler/NotificationHandlerImpl.java index c193f59ce..d7254aa47 100644 --- a/src/main/java/com/somemore/notification/handler/NotificationHandlerImpl.java +++ b/src/main/java/com/somemore/notification/handler/NotificationHandlerImpl.java @@ -8,9 +8,11 @@ import com.somemore.sse.usecase.SseUseCase; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; @Component @RequiredArgsConstructor +@Transactional public class NotificationHandlerImpl implements NotificationHandler { private final NotificationRepository notificationRepository; From f00354e802d30c39169d9f558ea9ba9a985b2a32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Sun, 8 Dec 2024 19:13:50 +0900 Subject: [PATCH 06/12] =?UTF-8?q?feat(MessageConverter):=20buildVolunteerR?= =?UTF-8?q?eviewRequestNotification=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - buildVolunteerApplyStatusChangeNotification 와 형태가 비슷해서 리팩토링 예정. - createVolunteerApplyStatusChangeNotificationTitle dafault를 명확하게 예외로 처리. --- .../converter/MessageConverter.java | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/somemore/notification/converter/MessageConverter.java b/src/main/java/com/somemore/notification/converter/MessageConverter.java index 0dbe39005..37e400f3a 100644 --- a/src/main/java/com/somemore/notification/converter/MessageConverter.java +++ b/src/main/java/com/somemore/notification/converter/MessageConverter.java @@ -1,11 +1,13 @@ package com.somemore.notification.converter; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.somemore.facade.event.VolunteerReviewRequestEvent; import com.somemore.notification.domain.Notification; import com.somemore.notification.domain.NotificationSubType; import com.somemore.volunteerapply.domain.ApplyStatus; -import com.somemore.volunteerapply.domain.VolunteerApplyStatusChangeEvent; +import com.somemore.volunteerapply.event.VolunteerApplyStatusChangeEvent; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -24,7 +26,7 @@ public Notification from(String message) { return switch (NotificationSubType.from(eventType)) { case NOTE_BLAH_BLAH -> throw new UnsupportedOperationException("NOTE 알림 타입 처리 로직 미구현"); - case REVIEW_BLAH_BLAH -> throw new UnsupportedOperationException("REVIEW 알림 타입 처리 로직 미구현"); + case VOLUNTEER_REVIEW_REQUEST -> buildVolunteerReviewRequestNotification(message); case VOLUNTEER_APPLY_STATUS_CHANGE -> buildVolunteerApplyStatusChangeNotification(message); }; } catch (Exception e) { @@ -33,32 +35,40 @@ public Notification from(String message) { } } + private Notification buildVolunteerReviewRequestNotification(String message) throws JsonProcessingException { + VolunteerReviewRequestEvent event = objectMapper.readValue(message, VolunteerReviewRequestEvent.class); + + return Notification.builder() + .receiverId(event.getVolunteerId()) + .title(createVolunteerReviewRequestNotificationTitle()) + .type(NotificationSubType.VOLUNTEER_REVIEW_REQUEST) + .relatedId(event.getRecruitBoardId()) + .build(); + } + private Notification buildVolunteerApplyStatusChangeNotification(String message) throws Exception { VolunteerApplyStatusChangeEvent event = objectMapper.readValue(message, VolunteerApplyStatusChangeEvent.class); return Notification.builder() - .receiverId(event.getReceiverId()) - .title(buildNotificationTitle(event.getNewStatus())) + .receiverId(event.getVolunteerId()) + .title(createVolunteerApplyStatusChangeNotificationTitle(event.getNewStatus())) .type(NotificationSubType.VOLUNTEER_APPLY_STATUS_CHANGE) .relatedId(event.getRecruitBoardId()) .build(); } - private Notification handleNoteEvent(String message) { - // TODO: NOTE 이벤트를 처리하는 로직 구현 - throw new UnsupportedOperationException("NOTE 알림 타입 처리 로직 미구현"); - } - - private Notification handleReviewEvent(String message) { - // TODO: System 이벤트를 처리하는 로직 구현 - throw new UnsupportedOperationException("REVIEW 알림 타입 처리 로직 미구현"); + private String createVolunteerReviewRequestNotificationTitle() { + return "최근 활동하신 활동의 후기를 작성해 주세요!"; } - private String buildNotificationTitle(ApplyStatus newStatus) { + private String createVolunteerApplyStatusChangeNotificationTitle(ApplyStatus newStatus) { return switch (newStatus) { case APPROVED -> "봉사 활동 신청이 승인되었습니다."; case REJECTED -> "봉사 활동 신청이 거절되었습니다."; - default -> "봉사 활동 신청 상태가 변경되었습니다."; + default -> { + log.error("올바르지 않은 봉사 신청 상태입니다: {}", newStatus); + throw new IllegalArgumentException(); + } }; } } From d20790c8e38cf7d92bc330ab156c21cfbc776661 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Sun, 8 Dec 2024 20:05:51 +0900 Subject: [PATCH 07/12] =?UTF-8?q?fix(event):=20JsonProperty=EC=99=80=20?= =?UTF-8?q?=ED=95=84=EB=93=9C=20=EB=AA=85=20=EB=A7=9E=EC=B6=94=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/somemore/facade/event/VolunteerReviewRequestEvent.java | 2 +- .../volunteerapply/event/VolunteerApplyStatusChangeEvent.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/somemore/facade/event/VolunteerReviewRequestEvent.java b/src/main/java/com/somemore/facade/event/VolunteerReviewRequestEvent.java index ef19f4711..67aa39d1b 100644 --- a/src/main/java/com/somemore/facade/event/VolunteerReviewRequestEvent.java +++ b/src/main/java/com/somemore/facade/event/VolunteerReviewRequestEvent.java @@ -21,7 +21,7 @@ public class VolunteerReviewRequestEvent extends ServerEvent Date: Sun, 8 Dec 2024 20:06:16 +0900 Subject: [PATCH 08/12] =?UTF-8?q?test(NotificationHandler):=20createdAt=20?= =?UTF-8?q?null=20check=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../somemore/notification/handler/NotificationHandlerTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/com/somemore/notification/handler/NotificationHandlerTest.java b/src/test/java/com/somemore/notification/handler/NotificationHandlerTest.java index 0f1546713..48ad33e97 100644 --- a/src/test/java/com/somemore/notification/handler/NotificationHandlerTest.java +++ b/src/test/java/com/somemore/notification/handler/NotificationHandlerTest.java @@ -61,5 +61,7 @@ void handle() { assertThat(savedNotification.getRelatedId()).isEqualTo(456L); // 프론트 요구사항: 123L(봉사신청아이디), 456L(모집글아이디) assertThat(savedNotification.isRead()).isFalse(); assertThat(savedNotification.getCreatedAt()).isEqualTo(notification.getCreatedAt()); + assertThat(savedNotification.getCreatedAt()).isNotNull(); } + } From d6c118e58fa8b28b2e2d5d4d009bec30e01b5bf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Sun, 8 Dec 2024 20:38:42 +0900 Subject: [PATCH 09/12] =?UTF-8?q?feat(event):=20=EC=97=AD=EC=A7=81?= =?UTF-8?q?=EB=A0=AC=ED=99=94=20=ED=95=84=EC=88=98=20=ED=95=84=EB=93=9C=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../facade/event/VolunteerReviewRequestEvent.java | 8 ++++---- .../somemore/global/common/event/ServerEvent.java | 6 +++--- .../event/VolunteerApplyStatusChangeEvent.java | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/somemore/facade/event/VolunteerReviewRequestEvent.java b/src/main/java/com/somemore/facade/event/VolunteerReviewRequestEvent.java index 67aa39d1b..2e7e43a82 100644 --- a/src/main/java/com/somemore/facade/event/VolunteerReviewRequestEvent.java +++ b/src/main/java/com/somemore/facade/event/VolunteerReviewRequestEvent.java @@ -21,10 +21,10 @@ public class VolunteerReviewRequestEvent extends ServerEvent> { private final LocalDateTime createdAt; protected ServerEvent( - @JsonProperty("type") ServerEventType type, - @JsonProperty("subType") T subType, - @JsonProperty("createdAt") LocalDateTime createdAt + @JsonProperty(value = "type", required = true) ServerEventType type, + @JsonProperty(value = "subType", required = true) T subType, + @JsonProperty(value = "createdAt", required = true) LocalDateTime createdAt ) { this.type = type; this.subType = subType; diff --git a/src/main/java/com/somemore/volunteerapply/event/VolunteerApplyStatusChangeEvent.java b/src/main/java/com/somemore/volunteerapply/event/VolunteerApplyStatusChangeEvent.java index 77e8e9b0a..bbfc62569 100644 --- a/src/main/java/com/somemore/volunteerapply/event/VolunteerApplyStatusChangeEvent.java +++ b/src/main/java/com/somemore/volunteerapply/event/VolunteerApplyStatusChangeEvent.java @@ -25,12 +25,12 @@ public class VolunteerApplyStatusChangeEvent extends ServerEvent Date: Sun, 8 Dec 2024 20:39:05 +0900 Subject: [PATCH 10/12] =?UTF-8?q?test(MessageConverter):=20=EB=A9=94?= =?UTF-8?q?=EC=8B=9C=EC=A7=80=20=EC=BB=A8=EB=B2=84=ED=8C=85=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../converter/MessageConverterTest.java | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 src/test/java/com/somemore/notification/converter/MessageConverterTest.java diff --git a/src/test/java/com/somemore/notification/converter/MessageConverterTest.java b/src/test/java/com/somemore/notification/converter/MessageConverterTest.java new file mode 100644 index 000000000..e161e6b11 --- /dev/null +++ b/src/test/java/com/somemore/notification/converter/MessageConverterTest.java @@ -0,0 +1,104 @@ +package com.somemore.notification.converter; + +import com.somemore.IntegrationTestSupport; +import com.somemore.notification.domain.Notification; +import com.somemore.notification.domain.NotificationSubType; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +class MessageConverterTest extends IntegrationTestSupport { + + @Autowired + private MessageConverter messageConverter; + + @Test + @DisplayName("VOLUNTEER_REVIEW_REQUEST 메시지를 변환하면 Notification 객체를 반환한다") + void testVolunteerReviewRequestConversion() { + // given + String message = """ + { + "type": "NOTIFICATION", + "subType": "VOLUNTEER_REVIEW_REQUEST", + "volunteerId": "123e4567-e89b-12d3-a456-426614174000", + "volunteerApplyId": "1", + "centerId": "123e4567-e89b-12d3-a456-426614174001", + "recruitBoardId": 456, + "createdAt": "2024-12-05T10:00:00" + } + """; + + // when + Notification notification = messageConverter.from(message); + + // then + assertThat(notification.getReceiverId()).isEqualTo(UUID.fromString("123e4567-e89b-12d3-a456-426614174000")); + assertThat(notification.getTitle()).isEqualTo("최근 활동하신 활동의 후기를 작성해 주세요!"); + assertThat(notification.getType()).isEqualTo(NotificationSubType.VOLUNTEER_REVIEW_REQUEST); + assertThat(notification.getRelatedId()).isEqualTo(456L); + } + + @Test + @DisplayName("임의의 필드가 추가된 VOLUNTEER_APPLY_STATUS_CHANGE 메시지를 변환해도 Notification 객체를 반환한다") + void testVolunteerApplyStatusChangeConversion() { + // given + String message = """ + { + "extraField": "this should be ignored", + "extraField": "this should be ignored", + "extraField": "this should be ignored", + "extraField": "this should be ignored", + "extraField": "this should be ignored", + "type": "NOTIFICATION", + "subType": "VOLUNTEER_APPLY_STATUS_CHANGE", + "volunteerId": "123e4567-e89b-12d3-a456-426614174000", + "centerId": "123e4567-e89b-12d3-a456-426614174001", + "volunteerApplyId": "1", + "recruitBoardId": 456, + "oldStatus": "WAITING", + "newStatus": "APPROVED", + "createdAt": "2024-12-05T10:00:00" + } + """; + + // when + Notification notification = messageConverter.from(message); + + // then + assertThat(notification.getReceiverId()).isEqualTo(UUID.fromString("123e4567-e89b-12d3-a456-426614174000")); + assertThat(notification.getTitle()).isEqualTo("봉사 활동 신청이 승인되었습니다."); + assertThat(notification.getType()).isEqualTo(NotificationSubType.VOLUNTEER_APPLY_STATUS_CHANGE); + assertThat(notification.getRelatedId()).isEqualTo(456L); + } + + @Test + @DisplayName("잘못된 JSON 메시지를 변환하면 IllegalStateException을 던진다") + void testInvalidJson() { + // given + String invalidMessage = "{ invalid-json }"; + + // when + // then + assertThrows(IllegalStateException.class, () -> messageConverter.from(invalidMessage)); + } + + @Test + @DisplayName("필수 필드가 누락된 메시지를 변환하면 IllegalStateException을 던진다") + void testMissingFields() { + // given + String messageWithMissingFields = """ + { + "type": "NOTIFICATION", + "subType": "VOLUNTEER_REVIEW_REQUEST" + } + """; + + // when & then + assertThrows(IllegalStateException.class, () -> messageConverter.from(messageWithMissingFields)); + } +} \ No newline at end of file From 618b9a416516e075a6dbb2a3cb05491b029db760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Sun, 8 Dec 2024 20:43:40 +0900 Subject: [PATCH 11/12] =?UTF-8?q?test(NotificationHandler):=20=EB=A9=94?= =?UTF-8?q?=EC=8B=9C=EC=A7=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../somemore/notification/handler/NotificationHandlerTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/somemore/notification/handler/NotificationHandlerTest.java b/src/test/java/com/somemore/notification/handler/NotificationHandlerTest.java index 48ad33e97..80c07db63 100644 --- a/src/test/java/com/somemore/notification/handler/NotificationHandlerTest.java +++ b/src/test/java/com/somemore/notification/handler/NotificationHandlerTest.java @@ -35,10 +35,11 @@ void handle() { { "type": "NOTIFICATION", "subType": "VOLUNTEER_APPLY_STATUS_CHANGE", - "receiverId": "123e4567-e89b-12d3-a456-426614174000", + "volunteerId": "123e4567-e89b-12d3-a456-426614174000", "volunteerApplyId": 123, "centerId": "123e4567-e89b-12d3-a456-426614174001", "recruitBoardId": 456, + "oldStatus": "WAITING", "newStatus": "APPROVED", "createdAt": "2024-12-05T10:00:00" } From 93689928462c844a7f190f78d45104efdf45c8c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Sun, 8 Dec 2024 20:59:14 +0900 Subject: [PATCH 12/12] =?UTF-8?q?refactor:=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EB=AA=85=EC=8B=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/somemore/notification/converter/MessageConverter.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/somemore/notification/converter/MessageConverter.java b/src/main/java/com/somemore/notification/converter/MessageConverter.java index 37e400f3a..60bb54c87 100644 --- a/src/main/java/com/somemore/notification/converter/MessageConverter.java +++ b/src/main/java/com/somemore/notification/converter/MessageConverter.java @@ -1,6 +1,7 @@ package com.somemore.notification.converter; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.somemore.facade.event.VolunteerReviewRequestEvent; @@ -46,7 +47,7 @@ private Notification buildVolunteerReviewRequestNotification(String message) thr .build(); } - private Notification buildVolunteerApplyStatusChangeNotification(String message) throws Exception { + private Notification buildVolunteerApplyStatusChangeNotification(String message) throws JsonProcessingException { VolunteerApplyStatusChangeEvent event = objectMapper.readValue(message, VolunteerApplyStatusChangeEvent.class); return Notification.builder()