diff --git a/src/main/java/com/somemore/notification/converter/MessageConverter.java b/src/main/java/com/somemore/notification/converter/MessageConverter.java index 8c8a241bc..40453059c 100644 --- a/src/main/java/com/somemore/notification/converter/MessageConverter.java +++ b/src/main/java/com/somemore/notification/converter/MessageConverter.java @@ -8,6 +8,7 @@ import com.somemore.notification.domain.Notification; import com.somemore.notification.domain.NotificationSubType; import com.somemore.volunteerapply.domain.ApplyStatus; +import com.somemore.volunteerapply.event.VolunteerApplyEvent; import com.somemore.volunteerapply.event.VolunteerApplyStatusChangeEvent; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -30,6 +31,7 @@ public Notification from(String message) { case VOLUNTEER_REVIEW_REQUEST -> buildVolunteerReviewRequestNotification(message); case VOLUNTEER_APPLY_STATUS_CHANGE -> buildVolunteerApplyStatusChangeNotification(message); case COMMENT_ADDED -> buildCommentAddedNotification(message); + case VOLUNTEER_APPLY -> buildVolunteerApplyNotification(message); }; } catch (Exception e) { log.error(e.getMessage()); @@ -70,6 +72,17 @@ private Notification buildCommentAddedNotification(String message) throws JsonPr .build(); } + private Notification buildVolunteerApplyNotification(String message) throws JsonProcessingException { + VolunteerApplyEvent event = objectMapper.readValue(message, VolunteerApplyEvent.class); + + return Notification.builder() + .receiverId(event.getCenterId()) + .title(createVolunteerApplyNotificationTitle()) + .type(NotificationSubType.VOLUNTEER_APPLY) + .relatedId(event.getRecruitBoardId()) + .build(); + } + private String createVolunteerReviewRequestNotificationTitle() { return "최근 활동하신 활동의 후기를 작성해 주세요!"; } @@ -88,4 +101,8 @@ private String createVolunteerApplyStatusChangeNotificationTitle(ApplyStatus new private String createCommentAddedNotificationTitle() { return "새로운 댓글이 작성되었습니다."; } + + private String createVolunteerApplyNotificationTitle() { + return "봉사 활동 모집에 새로운 신청이 있습니다."; + } } diff --git a/src/main/java/com/somemore/notification/domain/NotificationSubType.java b/src/main/java/com/somemore/notification/domain/NotificationSubType.java index 15fa91d9a..cb7606d35 100644 --- a/src/main/java/com/somemore/notification/domain/NotificationSubType.java +++ b/src/main/java/com/somemore/notification/domain/NotificationSubType.java @@ -9,7 +9,8 @@ public enum NotificationSubType { NOTE_BLAH_BLAH("쪽지"), VOLUNTEER_REVIEW_REQUEST("봉사 후기 요청"), VOLUNTEER_APPLY_STATUS_CHANGE("신청 상태 변경"), - COMMENT_ADDED("댓글 대댓글 추가") + COMMENT_ADDED("댓글 대댓글 추가"), + VOLUNTEER_APPLY("봉사 신청"), ; private final String description; diff --git a/src/main/java/com/somemore/volunteerapply/event/VolunteerApplyEvent.java b/src/main/java/com/somemore/volunteerapply/event/VolunteerApplyEvent.java new file mode 100644 index 000000000..827ebd38b --- /dev/null +++ b/src/main/java/com/somemore/volunteerapply/event/VolunteerApplyEvent.java @@ -0,0 +1,35 @@ +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 lombok.Getter; +import lombok.experimental.SuperBuilder; + +import java.time.LocalDateTime; +import java.util.UUID; + +@Getter +@SuperBuilder +public class VolunteerApplyEvent extends ServerEvent { + private final UUID volunteerId; + private final Long volunteerApplyId; + private final UUID centerId; + private final Long recruitBoardId; + + @JsonCreator + public VolunteerApplyEvent( + @JsonProperty(value = "volunteerId", required = true) UUID volunteerId, + @JsonProperty(value = "volunteerApplyId", required = true) Long volunteerApplyId, + @JsonProperty(value = "centerId", required = true) UUID centerId, + @JsonProperty(value = "recruitBoardId", required = true) Long recruitBoardId + ) { + super(ServerEventType.NOTIFICATION, NotificationSubType.VOLUNTEER_APPLY, LocalDateTime.now()); + this.volunteerId = volunteerId; + this.volunteerApplyId = volunteerApplyId; + this.centerId = centerId; + this.recruitBoardId = recruitBoardId; + } +} diff --git a/src/main/java/com/somemore/volunteerapply/service/ApplyVolunteerApplyService.java b/src/main/java/com/somemore/volunteerapply/service/ApplyVolunteerApplyService.java index e7a609838..0c52ac888 100644 --- a/src/main/java/com/somemore/volunteerapply/service/ApplyVolunteerApplyService.java +++ b/src/main/java/com/somemore/volunteerapply/service/ApplyVolunteerApplyService.java @@ -3,11 +3,15 @@ import static com.somemore.global.exception.ExceptionMessage.DUPLICATE_APPLICATION; import static com.somemore.global.exception.ExceptionMessage.RECRUITMENT_NOT_OPEN; +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.volunteerapply.domain.VolunteerApply; import com.somemore.volunteerapply.dto.request.VolunteerApplyCreateRequestDto; +import com.somemore.volunteerapply.event.VolunteerApplyEvent; import com.somemore.volunteerapply.repository.VolunteerApplyRepository; import com.somemore.volunteerapply.usecase.ApplyVolunteerApplyUseCase; import java.util.UUID; @@ -22,6 +26,7 @@ public class ApplyVolunteerApplyService implements ApplyVolunteerApplyUseCase { private final VolunteerApplyRepository volunteerApplyRepository; private final RecruitBoardQueryUseCase recruitBoardQueryUseCase; + private final ServerEventPublisher serverEventPublisher; @Override public Long apply(VolunteerApplyCreateRequestDto requestDto, UUID volunteerId) { @@ -33,6 +38,8 @@ public Long apply(VolunteerApplyCreateRequestDto requestDto, UUID volunteerId) { VolunteerApply apply = requestDto.toEntity(volunteerId); volunteerApplyRepository.save(apply); + publishVolunteerApplyEvent(apply, board); + return apply.getId(); } @@ -50,4 +57,17 @@ private void validateDuplicatedApply(UUID volunteerId, RecruitBoard board) { throw new BadRequestException(DUPLICATE_APPLICATION); } } + + private void publishVolunteerApplyEvent(VolunteerApply apply, RecruitBoard board) { + VolunteerApplyEvent event = VolunteerApplyEvent.builder() + .type(ServerEventType.NOTIFICATION) + .subType(NotificationSubType.VOLUNTEER_APPLY) + .volunteerId(apply.getVolunteerId()) + .volunteerApplyId(apply.getId()) + .centerId(board.getCenterId()) + .recruitBoardId(board.getId()) + .build(); + + serverEventPublisher.publish(event); + } }