Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -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;
Expand All @@ -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());
Expand Down Expand Up @@ -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 "최근 활동하신 활동의 후기를 작성해 주세요!";
}
Expand All @@ -88,4 +101,8 @@ private String createVolunteerApplyStatusChangeNotificationTitle(ApplyStatus new
private String createCommentAddedNotificationTitle() {
return "새로운 댓글이 작성되었습니다.";
}

private String createVolunteerApplyNotificationTitle() {
return "봉사 활동 모집에 새로운 신청이 있습니다.";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<NotificationSubType> {
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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();
}

Expand All @@ -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);
}
}
Loading