Skip to content

Commit 404ae84

Browse files
authored
Feature/217 봉사 신청 알림 (#218)
* feat(NotificationSubType): VOLUNTEER_APPLY 추가 * feat(VolunteerApplyEvent): 봉사 신청 이벤트 추가 * feat(ApplyVolunteerApplyService): 봉사 신청 이벤트 발행 * feat(MessageConverter): 봉사 신청 이벤트 메시지 컨버팅 처리
1 parent b491e37 commit 404ae84

File tree

4 files changed

+74
-1
lines changed

4 files changed

+74
-1
lines changed

src/main/java/com/somemore/notification/converter/MessageConverter.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.somemore.notification.domain.Notification;
99
import com.somemore.notification.domain.NotificationSubType;
1010
import com.somemore.volunteerapply.domain.ApplyStatus;
11+
import com.somemore.volunteerapply.event.VolunteerApplyEvent;
1112
import com.somemore.volunteerapply.event.VolunteerApplyStatusChangeEvent;
1213
import lombok.RequiredArgsConstructor;
1314
import lombok.extern.slf4j.Slf4j;
@@ -30,6 +31,7 @@ public Notification from(String message) {
3031
case VOLUNTEER_REVIEW_REQUEST -> buildVolunteerReviewRequestNotification(message);
3132
case VOLUNTEER_APPLY_STATUS_CHANGE -> buildVolunteerApplyStatusChangeNotification(message);
3233
case COMMENT_ADDED -> buildCommentAddedNotification(message);
34+
case VOLUNTEER_APPLY -> buildVolunteerApplyNotification(message);
3335
};
3436
} catch (Exception e) {
3537
log.error(e.getMessage());
@@ -70,6 +72,17 @@ private Notification buildCommentAddedNotification(String message) throws JsonPr
7072
.build();
7173
}
7274

75+
private Notification buildVolunteerApplyNotification(String message) throws JsonProcessingException {
76+
VolunteerApplyEvent event = objectMapper.readValue(message, VolunteerApplyEvent.class);
77+
78+
return Notification.builder()
79+
.receiverId(event.getCenterId())
80+
.title(createVolunteerApplyNotificationTitle())
81+
.type(NotificationSubType.VOLUNTEER_APPLY)
82+
.relatedId(event.getRecruitBoardId())
83+
.build();
84+
}
85+
7386
private String createVolunteerReviewRequestNotificationTitle() {
7487
return "최근 활동하신 활동의 후기를 작성해 주세요!";
7588
}
@@ -88,4 +101,8 @@ private String createVolunteerApplyStatusChangeNotificationTitle(ApplyStatus new
88101
private String createCommentAddedNotificationTitle() {
89102
return "새로운 댓글이 작성되었습니다.";
90103
}
104+
105+
private String createVolunteerApplyNotificationTitle() {
106+
return "봉사 활동 모집에 새로운 신청이 있습니다.";
107+
}
91108
}

src/main/java/com/somemore/notification/domain/NotificationSubType.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ public enum NotificationSubType {
99
NOTE_BLAH_BLAH("쪽지"),
1010
VOLUNTEER_REVIEW_REQUEST("봉사 후기 요청"),
1111
VOLUNTEER_APPLY_STATUS_CHANGE("신청 상태 변경"),
12-
COMMENT_ADDED("댓글 대댓글 추가")
12+
COMMENT_ADDED("댓글 대댓글 추가"),
13+
VOLUNTEER_APPLY("봉사 신청"),
1314
;
1415

1516
private final String description;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.somemore.volunteerapply.event;
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import com.somemore.global.common.event.ServerEvent;
6+
import com.somemore.global.common.event.ServerEventType;
7+
import com.somemore.notification.domain.NotificationSubType;
8+
import lombok.Getter;
9+
import lombok.experimental.SuperBuilder;
10+
11+
import java.time.LocalDateTime;
12+
import java.util.UUID;
13+
14+
@Getter
15+
@SuperBuilder
16+
public class VolunteerApplyEvent extends ServerEvent<NotificationSubType> {
17+
private final UUID volunteerId;
18+
private final Long volunteerApplyId;
19+
private final UUID centerId;
20+
private final Long recruitBoardId;
21+
22+
@JsonCreator
23+
public VolunteerApplyEvent(
24+
@JsonProperty(value = "volunteerId", required = true) UUID volunteerId,
25+
@JsonProperty(value = "volunteerApplyId", required = true) Long volunteerApplyId,
26+
@JsonProperty(value = "centerId", required = true) UUID centerId,
27+
@JsonProperty(value = "recruitBoardId", required = true) Long recruitBoardId
28+
) {
29+
super(ServerEventType.NOTIFICATION, NotificationSubType.VOLUNTEER_APPLY, LocalDateTime.now());
30+
this.volunteerId = volunteerId;
31+
this.volunteerApplyId = volunteerApplyId;
32+
this.centerId = centerId;
33+
this.recruitBoardId = recruitBoardId;
34+
}
35+
}

src/main/java/com/somemore/volunteerapply/service/ApplyVolunteerApplyService.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
import static com.somemore.global.exception.ExceptionMessage.DUPLICATE_APPLICATION;
44
import static com.somemore.global.exception.ExceptionMessage.RECRUITMENT_NOT_OPEN;
55

6+
import com.somemore.global.common.event.ServerEventPublisher;
7+
import com.somemore.global.common.event.ServerEventType;
68
import com.somemore.global.exception.BadRequestException;
9+
import com.somemore.notification.domain.NotificationSubType;
710
import com.somemore.recruitboard.domain.RecruitBoard;
811
import com.somemore.recruitboard.usecase.query.RecruitBoardQueryUseCase;
912
import com.somemore.volunteerapply.domain.VolunteerApply;
1013
import com.somemore.volunteerapply.dto.request.VolunteerApplyCreateRequestDto;
14+
import com.somemore.volunteerapply.event.VolunteerApplyEvent;
1115
import com.somemore.volunteerapply.repository.VolunteerApplyRepository;
1216
import com.somemore.volunteerapply.usecase.ApplyVolunteerApplyUseCase;
1317
import java.util.UUID;
@@ -22,6 +26,7 @@ public class ApplyVolunteerApplyService implements ApplyVolunteerApplyUseCase {
2226

2327
private final VolunteerApplyRepository volunteerApplyRepository;
2428
private final RecruitBoardQueryUseCase recruitBoardQueryUseCase;
29+
private final ServerEventPublisher serverEventPublisher;
2530

2631
@Override
2732
public Long apply(VolunteerApplyCreateRequestDto requestDto, UUID volunteerId) {
@@ -33,6 +38,8 @@ public Long apply(VolunteerApplyCreateRequestDto requestDto, UUID volunteerId) {
3338
VolunteerApply apply = requestDto.toEntity(volunteerId);
3439
volunteerApplyRepository.save(apply);
3540

41+
publishVolunteerApplyEvent(apply, board);
42+
3643
return apply.getId();
3744
}
3845

@@ -50,4 +57,17 @@ private void validateDuplicatedApply(UUID volunteerId, RecruitBoard board) {
5057
throw new BadRequestException(DUPLICATE_APPLICATION);
5158
}
5259
}
60+
61+
private void publishVolunteerApplyEvent(VolunteerApply apply, RecruitBoard board) {
62+
VolunteerApplyEvent event = VolunteerApplyEvent.builder()
63+
.type(ServerEventType.NOTIFICATION)
64+
.subType(NotificationSubType.VOLUNTEER_APPLY)
65+
.volunteerId(apply.getVolunteerId())
66+
.volunteerApplyId(apply.getId())
67+
.centerId(board.getCenterId())
68+
.recruitBoardId(board.getId())
69+
.build();
70+
71+
serverEventPublisher.publish(event);
72+
}
5373
}

0 commit comments

Comments
 (0)