33import static com .somemore .global .exception .ExceptionMessage .DUPLICATE_APPLICATION ;
44import 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 ;
68import com .somemore .global .exception .BadRequestException ;
9+ import com .somemore .notification .domain .NotificationSubType ;
710import com .somemore .recruitboard .domain .RecruitBoard ;
811import com .somemore .recruitboard .usecase .query .RecruitBoardQueryUseCase ;
912import com .somemore .volunteerapply .domain .VolunteerApply ;
1013import com .somemore .volunteerapply .dto .request .VolunteerApplyCreateRequestDto ;
14+ import com .somemore .volunteerapply .event .VolunteerApplyEvent ;
1115import com .somemore .volunteerapply .repository .VolunteerApplyRepository ;
1216import com .somemore .volunteerapply .usecase .ApplyVolunteerApplyUseCase ;
1317import 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