55import static com .somemore .global .exception .ExceptionMessage .UNAUTHORIZED_RECRUIT_BOARD ;
66import static com .somemore .volunteerapply .domain .ApplyStatus .REJECTED ;
77
8+ import com .somemore .global .common .event .ServerEventPublisher ;
89import com .somemore .global .exception .BadRequestException ;
910import com .somemore .recruitboard .domain .RecruitBoard ;
1011import com .somemore .recruitboard .usecase .query .RecruitBoardQueryUseCase ;
12+ import com .somemore .volunteerapply .domain .ApplyStatus ;
1113import com .somemore .volunteerapply .domain .VolunteerApply ;
14+ import com .somemore .volunteerapply .event .VolunteerApplyStatusChangeEvent ;
1215import com .somemore .volunteerapply .repository .VolunteerApplyRepository ;
1316import com .somemore .volunteerapply .usecase .RejectVolunteerApplyUseCase ;
1417import 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