66import grep .neogulcoder .domain .alram .repository .AlarmRepository ;
77import grep .neogulcoder .domain .alram .type .AlarmType ;
88import grep .neogulcoder .domain .alram .type .DomainType ;
9+ import grep .neogulcoder .domain .recruitment .comment .event .RecruitmentPostCommentEvent ;
910import grep .neogulcoder .domain .recruitment .post .RecruitmentPost ;
1011import grep .neogulcoder .domain .recruitment .post .repository .RecruitmentPostRepository ;
1112import grep .neogulcoder .domain .study .Study ;
2122import grep .neogulcoder .domain .studyapplication .event .ApplicationEvent ;
2223import grep .neogulcoder .domain .studyapplication .event .ApplicationStatusChangedEvent ;
2324import grep .neogulcoder .domain .studyapplication .repository .ApplicationRepository ;
25+ import grep .neogulcoder .domain .studypost .StudyPost ;
26+ import grep .neogulcoder .domain .studypost .StudyPostErrorCode ;
27+ import grep .neogulcoder .domain .studypost .comment .event .StudyPostCommentEvent ;
28+ import grep .neogulcoder .domain .studypost .repository .StudyPostRepository ;
2429import grep .neogulcoder .domain .timevote .event .TimeVotePeriodCreatedEvent ;
2530import grep .neogulcoder .global .exception .business .BusinessException ;
2631import grep .neogulcoder .global .exception .business .NotFoundException ;
2732import grep .neogulcoder .global .provider .finder .MessageFinder ;
28- import java .util .List ;
2933import lombok .RequiredArgsConstructor ;
3034import org .springframework .context .event .EventListener ;
3135import org .springframework .stereotype .Service ;
3236import org .springframework .transaction .annotation .Transactional ;
3337
34- import static grep .neogulcoder .domain .study .exception .code .StudyErrorCode .*;
35- import static grep .neogulcoder .domain .studyapplication .exception .code .ApplicationErrorCode .*;
36- import static grep .neogulcoder .domain .recruitment .RecruitmentErrorCode .*;
38+ import java .util .List ;
39+
40+ import static grep .neogulcoder .domain .recruitment .RecruitmentErrorCode .NOT_FOUND ;
41+ import static grep .neogulcoder .domain .study .exception .code .StudyErrorCode .STUDY_LEADER_NOT_FOUND ;
42+ import static grep .neogulcoder .domain .study .exception .code .StudyErrorCode .STUDY_NOT_FOUND ;
43+ import static grep .neogulcoder .domain .studyapplication .exception .code .ApplicationErrorCode .APPLICATION_NOT_FOUND ;
44+ import static grep .neogulcoder .domain .studyapplication .exception .code .ApplicationErrorCode .APPLICATION_PARTICIPANT_LIMIT_EXCEEDED ;
3745
3846@ Service
3947@ RequiredArgsConstructor
@@ -43,61 +51,62 @@ public class AlarmService {
4351 private final AlarmRepository alarmRepository ;
4452 private final MessageFinder messageFinder ;
4553 private final StudyRepository studyRepository ;
54+ private final StudyPostRepository studyPostRepository ;
4655 private final StudyMemberQueryRepository studyMemberQueryRepository ;
4756 private final StudyMemberRepository studyMemberRepository ;
4857 private final RecruitmentPostRepository recruitmentPostRepository ;
4958 private final ApplicationRepository applicationRepository ;
5059
5160 @ Transactional
5261 public void saveAlarm (Long receiverId , AlarmType alarmType , DomainType domainType ,
53- Long domainId ) {
62+ Long domainId ) {
5463 String message = messageFinder .findMessage (alarmType , domainType , domainId );
5564 alarmRepository .save (Alarm .init (alarmType , receiverId , domainType , domainId , message ));
5665 }
5766
5867 public List <AlarmResponse > getAllUncheckedAlarms (Long receiverUserId ) {
5968 return alarmRepository .findAllByReceiverUserIdAndCheckedFalse (receiverUserId ).stream ()
60- .map (alarm -> AlarmResponse .toResponse (
61- alarm .getId (),
62- alarm .getReceiverUserId (),
63- alarm .getAlarmType (),
64- alarm .getDomainType (),
65- alarm .getDomainId (),
66- alarm .getMessage (),
67- alarm .isChecked (),
68- alarm .getCreatedDate ()))
69- .toList ();
69+ .map (alarm -> AlarmResponse .toResponse (
70+ alarm .getId (),
71+ alarm .getReceiverUserId (),
72+ alarm .getAlarmType (),
73+ alarm .getDomainType (),
74+ alarm .getDomainId (),
75+ alarm .getMessage (),
76+ alarm .isChecked (),
77+ alarm .getCreatedDate ()))
78+ .toList ();
7079 }
7180
7281 public List <AlarmResponse > getAllAlarms (Long receiverUserId ) {
7382 return alarmRepository .findAllByReceiverUserId (receiverUserId ).stream ()
74- .map (alarm -> AlarmResponse .toResponse (
75- alarm .getId (),
76- alarm .getReceiverUserId (),
77- alarm .getAlarmType (),
78- alarm .getDomainType (),
79- alarm .getDomainId (),
80- alarm .getMessage (),
81- alarm .isChecked (),
82- alarm .getCreatedDate ()))
83- .toList ();
83+ .map (alarm -> AlarmResponse .toResponse (
84+ alarm .getId (),
85+ alarm .getReceiverUserId (),
86+ alarm .getAlarmType (),
87+ alarm .getDomainType (),
88+ alarm .getDomainId (),
89+ alarm .getMessage (),
90+ alarm .isChecked (),
91+ alarm .getCreatedDate ()))
92+ .toList ();
8493 }
8594
8695 @ Transactional
8796 public void checkAllAlarmWithoutInvite (Long receiverUserId ) {
8897 List <Alarm > alarms = alarmRepository .findAllByReceiverUserIdAndCheckedFalse (receiverUserId );
8998 alarms .stream ()
90- .filter (alarm -> alarm .getAlarmType () != AlarmType .INVITE )
91- .forEach (Alarm ::checkAlarm );
99+ .filter (alarm -> alarm .getAlarmType () != AlarmType .INVITE )
100+ .forEach (Alarm ::checkAlarm );
92101 }
93102
94103 @ EventListener
95104 public void handleStudyInviteEvent (StudyInviteEvent event ) {
96105 saveAlarm (
97- event .targetUserId (),
98- AlarmType .INVITE ,
99- DomainType .STUDY ,
100- event .studyId ()
106+ event .targetUserId (),
107+ AlarmType .INVITE ,
108+ DomainType .STUDY ,
109+ event .studyId ()
101110 );
102111 }
103112
@@ -122,15 +131,15 @@ public void rejectInvite(Long alarmId) {
122131 @ EventListener
123132 public void handleStudyExtendEvent (StudyExtendEvent event ) {
124133 List <StudyMember > members = studyMemberRepository .findAllByStudyIdAndActivatedTrue (
125- event .studyId ());
134+ event .studyId ());
126135
127136 for (StudyMember member : members ) {
128137 if (!member .isLeader ()) {
129138 saveAlarm (
130- member .getUserId (),
131- AlarmType .STUDY_EXTEND ,
132- DomainType .STUDY ,
133- event .studyId ()
139+ member .getUserId (),
140+ AlarmType .STUDY_EXTEND ,
141+ DomainType .STUDY ,
142+ event .studyId ()
134143 );
135144 }
136145 }
@@ -139,29 +148,29 @@ public void handleStudyExtendEvent(StudyExtendEvent event) {
139148 @ EventListener
140149 public void handleStudyExtensionReminderEvent (StudyExtensionReminderEvent event ) {
141150 StudyMember leader = studyMemberRepository .findByStudyIdAndRoleAndActivatedTrue (
142- event .studyId (), StudyMemberRole .LEADER )
143- .orElseThrow (() -> new BusinessException (STUDY_LEADER_NOT_FOUND ));
151+ event .studyId (), StudyMemberRole .LEADER )
152+ .orElseThrow (() -> new BusinessException (STUDY_LEADER_NOT_FOUND ));
144153
145154 saveAlarm (
146- leader .getUserId (),
147- AlarmType .STUDY_EXTENSION_REMINDER ,
148- DomainType .STUDY ,
149- event .studyId ()
155+ leader .getUserId (),
156+ AlarmType .STUDY_EXTENSION_REMINDER ,
157+ DomainType .STUDY ,
158+ event .studyId ()
150159 );
151160 }
152161
153162 @ EventListener
154163 public void handleTimeVotePeriodCreatedEvent (TimeVotePeriodCreatedEvent event ) {
155164 List <StudyMember > members = studyMemberRepository .findAllByStudyIdAndActivatedTrue (
156- event .studyId ());
165+ event .studyId ());
157166
158167 for (StudyMember member : members ) {
159168 if (!member .getUserId ().equals (event .excludedUserId ())) {
160169 saveAlarm (
161- member .getUserId (),
162- AlarmType .TIME_VOTE_REQUEST ,
163- DomainType .TIME_VOTE ,
164- event .studyId ()
170+ member .getUserId (),
171+ AlarmType .TIME_VOTE_REQUEST ,
172+ DomainType .TIME_VOTE ,
173+ event .studyId ()
165174 );
166175 }
167176 }
@@ -170,37 +179,83 @@ public void handleTimeVotePeriodCreatedEvent(TimeVotePeriodCreatedEvent event) {
170179 @ EventListener
171180 public void handleApplicationEvent (ApplicationEvent event ) {
172181 RecruitmentPost recruitmentPost = recruitmentPostRepository .findByIdAndActivatedTrue (event .recruitmentPostId ())
173- .orElseThrow (() -> new BusinessException (NOT_FOUND ));
182+ .orElseThrow (() -> new BusinessException (NOT_FOUND ));
174183
175184 saveAlarm (
176- recruitmentPost .getUserId (),
177- AlarmType .STUDY_APPLICATION ,
178- DomainType .RECRUITMENT_POST ,
179- event .recruitmentPostId ()
185+ recruitmentPost .getUserId (),
186+ AlarmType .STUDY_APPLICATION ,
187+ DomainType .RECRUITMENT_POST ,
188+ event .recruitmentPostId ()
180189 );
181190 }
182191
183192 @ EventListener
184193 public void handleApplicationStatusChangedEvent (ApplicationStatusChangedEvent event ) {
185194 StudyApplication application = applicationRepository .findByIdAndActivatedTrue (event .applicationId ())
186- .orElseThrow (() -> new BusinessException (APPLICATION_NOT_FOUND ));
195+ .orElseThrow (() -> new BusinessException (APPLICATION_NOT_FOUND ));
187196
188197 saveAlarm (
189- application .getUserId (),
190- event .alarmType (),
191- DomainType .STUDY_APPLICATION ,
192- application .getId ()
198+ application .getUserId (),
199+ event .alarmType (),
200+ DomainType .STUDY_APPLICATION ,
201+ application .getId ()
202+ );
203+ }
204+
205+ @ Transactional
206+ @ EventListener
207+ public void handleRecruitmentPostCommentEvent (RecruitmentPostCommentEvent event ) {
208+ RecruitmentPost recruitmentPost = recruitmentPostRepository .findById (event .getPostId ())
209+ .orElseThrow (() -> new NotFoundException (NOT_FOUND ));
210+
211+ String message = messageFinder .findMessage (
212+ AlarmType .RECRUITMENT_POST_COMMENT ,
213+ DomainType .RECRUITMENT_POST ,
214+ recruitmentPost .getId ()
215+ );
216+
217+ alarmRepository .save (
218+ Alarm .init (
219+ AlarmType .RECRUITMENT_POST_COMMENT ,
220+ event .getTargetUserId (),
221+ DomainType .RECRUITMENT_POST ,
222+ event .getPostId (),
223+ message
224+ )
225+ );
226+ }
227+
228+ @ Transactional
229+ @ EventListener
230+ public void handleStudyPostCommentEvent (StudyPostCommentEvent event ) {
231+ StudyPost studyPost = studyPostRepository .findById (event .getPostId ())
232+ .orElseThrow (() -> new NotFoundException (StudyPostErrorCode .NOT_FOUND_POST ));
233+
234+ String message = messageFinder .findMessage (
235+ AlarmType .STUDY_POST_COMMENT ,
236+ DomainType .STUDY_POST ,
237+ studyPost .getId ()
238+ );
239+
240+ alarmRepository .save (
241+ Alarm .init (
242+ AlarmType .STUDY_POST_COMMENT ,
243+ event .getTargetUserId (),
244+ DomainType .STUDY_POST ,
245+ event .getPostId (),
246+ message
247+ )
193248 );
194249 }
195250
196251 private Alarm findValidAlarm (Long alarmId ) {
197252 return alarmRepository .findById (alarmId )
198- .orElseThrow (() -> new NotFoundException (AlarmErrorCode .ALARM_NOT_FOUND ));
253+ .orElseThrow (() -> new NotFoundException (AlarmErrorCode .ALARM_NOT_FOUND ));
199254 }
200255
201256 private Study findValidStudy (Long studyId ) {
202257 return studyRepository .findById (studyId )
203- .orElseThrow (() -> new NotFoundException (STUDY_NOT_FOUND ));
258+ .orElseThrow (() -> new NotFoundException (STUDY_NOT_FOUND ));
204259 }
205260
206261 private void validateParticipantStudyLimit (Long userId ) {
0 commit comments