Skip to content

Commit fcd518a

Browse files
committed
feat(VolunteerApplyStatusChangeEvent): 거절 이벤트 처리
- 이전 상태와 현 상태 비교 검증. - 중복 코드 최소화.
1 parent b491e37 commit fcd518a

File tree

3 files changed

+43
-16
lines changed

3 files changed

+43
-16
lines changed

src/main/java/com/somemore/volunteerapply/event/VolunteerApplyStatusChangeEvent.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import com.somemore.global.common.event.ServerEvent;
66
import com.somemore.global.common.event.ServerEventType;
77
import com.somemore.notification.domain.NotificationSubType;
8+
import com.somemore.recruitboard.domain.RecruitBoard;
89
import com.somemore.volunteerapply.domain.ApplyStatus;
10+
import com.somemore.volunteerapply.domain.VolunteerApply;
911
import lombok.Getter;
1012
import lombok.experimental.SuperBuilder;
1113

@@ -40,4 +42,18 @@ public VolunteerApplyStatusChangeEvent(
4042
this.oldStatus = oldStatus;
4143
this.newStatus = newStatus;
4244
}
45+
46+
public static VolunteerApplyStatusChangeEvent from(VolunteerApply apply, RecruitBoard recruitBoard, ApplyStatus oldStatus) {
47+
48+
return VolunteerApplyStatusChangeEvent.builder()
49+
.type(ServerEventType.NOTIFICATION)
50+
.subType(NotificationSubType.VOLUNTEER_APPLY_STATUS_CHANGE)
51+
.volunteerId(apply.getVolunteerId())
52+
.volunteerApplyId(apply.getId())
53+
.centerId(recruitBoard.getCenterId())
54+
.recruitBoardId(recruitBoard.getId())
55+
.oldStatus(oldStatus)
56+
.newStatus(apply.getStatus())
57+
.build();
58+
}
4359
}

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

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package com.somemore.volunteerapply.service;
22

33
import com.somemore.global.common.event.ServerEventPublisher;
4-
import com.somemore.global.common.event.ServerEventType;
54
import com.somemore.global.exception.BadRequestException;
6-
import com.somemore.notification.domain.NotificationSubType;
75
import com.somemore.recruitboard.domain.RecruitBoard;
86
import com.somemore.recruitboard.usecase.query.RecruitBoardQueryUseCase;
97
import com.somemore.volunteerapply.domain.ApplyStatus;
@@ -65,18 +63,14 @@ private void validateBoardStatus(RecruitBoard recruitBoard) {
6563
}
6664
}
6765

68-
private void publishVolunteerApplyStatusChangeEvent(VolunteerApply apply, RecruitBoard recruitBoard, ApplyStatus oldStatus) {
69-
VolunteerApplyStatusChangeEvent event = VolunteerApplyStatusChangeEvent.builder()
70-
.type(ServerEventType.NOTIFICATION)
71-
.subType(NotificationSubType.VOLUNTEER_APPLY_STATUS_CHANGE)
72-
.volunteerId(apply.getVolunteerId())
73-
.volunteerApplyId(apply.getId())
74-
.centerId(recruitBoard.getCenterId())
75-
.recruitBoardId(recruitBoard.getId())
76-
.oldStatus(oldStatus)
77-
.newStatus(apply.getStatus())
78-
.build();
66+
private void publishVolunteerApplyStatusChangeEvent(VolunteerApply apply,
67+
RecruitBoard recruitBoard,
68+
ApplyStatus oldStatus) {
7969

80-
serverEventPublisher.publish(event);
70+
if (apply.getStatus() == oldStatus) {
71+
return;
72+
}
73+
74+
serverEventPublisher.publish(VolunteerApplyStatusChangeEvent.from(apply, recruitBoard, oldStatus));
8175
}
8276
}

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_RECRUIT_BOARD;
66
import static com.somemore.volunteerapply.domain.ApplyStatus.REJECTED;
77

8+
import com.somemore.global.common.event.ServerEventPublisher;
89
import com.somemore.global.exception.BadRequestException;
910
import com.somemore.recruitboard.domain.RecruitBoard;
1011
import com.somemore.recruitboard.usecase.query.RecruitBoardQueryUseCase;
12+
import com.somemore.volunteerapply.domain.ApplyStatus;
1113
import com.somemore.volunteerapply.domain.VolunteerApply;
14+
import com.somemore.volunteerapply.event.VolunteerApplyStatusChangeEvent;
1215
import com.somemore.volunteerapply.repository.VolunteerApplyRepository;
1316
import com.somemore.volunteerapply.usecase.RejectVolunteerApplyUseCase;
1417
import java.util.UUID;
@@ -23,20 +26,24 @@ public class RejectVolunteerApplyService implements RejectVolunteerApplyUseCase
2326

2427
private final VolunteerApplyRepository volunteerApplyRepository;
2528
private final RecruitBoardQueryUseCase recruitBoardQueryUseCase;
29+
private final ServerEventPublisher serverEventPublisher;
2630

2731
@Override
2832
public void reject(Long id, UUID centerId) {
29-
VolunteerApply apply = getApply(id);
33+
VolunteerApply apply = getVolunteerApply(id);
3034
RecruitBoard recruitBoard = recruitBoardQueryUseCase.getById(apply.getRecruitBoardId());
3135

3236
validateWriter(recruitBoard, centerId);
3337
validateBoardStatus(recruitBoard);
3438

39+
ApplyStatus oldStatus = apply.getStatus();
3540
apply.changeStatus(REJECTED);
3641
volunteerApplyRepository.save(apply);
42+
43+
publishVolunteerApplyStatusChangeEvent(apply, recruitBoard, oldStatus);
3744
}
3845

39-
private VolunteerApply getApply(Long id) {
46+
private VolunteerApply getVolunteerApply(Long id) {
4047
return volunteerApplyRepository.findById(id).orElseThrow(
4148
() -> new BadRequestException(NOT_EXISTS_VOLUNTEER_APPLY)
4249
);
@@ -55,4 +62,14 @@ private void validateBoardStatus(RecruitBoard recruitBoard) {
5562
}
5663
}
5764

65+
private void publishVolunteerApplyStatusChangeEvent(VolunteerApply apply,
66+
RecruitBoard recruitBoard,
67+
ApplyStatus oldStatus) {
68+
69+
if (apply.getStatus() == oldStatus) {
70+
return;
71+
}
72+
73+
serverEventPublisher.publish(VolunteerApplyStatusChangeEvent.from(apply, recruitBoard, oldStatus));
74+
}
5875
}

0 commit comments

Comments
 (0)