3737
3838import java .util .List ;
3939
40+ import static grep .neogulcoder .domain .alram .exception .code .AlarmErrorCode .ALREADY_CHECKED ;
4041import static grep .neogulcoder .domain .recruitment .RecruitmentErrorCode .NOT_FOUND ;
4142import static grep .neogulcoder .domain .study .exception .code .StudyErrorCode .STUDY_LEADER_NOT_FOUND ;
4243import static grep .neogulcoder .domain .study .exception .code .StudyErrorCode .STUDY_NOT_FOUND ;
@@ -113,18 +114,27 @@ public void handleStudyInviteEvent(StudyInviteEvent event) {
113114 @ Transactional
114115 public void acceptInvite (Long targetUserId , Long alarmId ) {
115116
117+ if (isChecked (targetUserId , alarmId )){
118+ throw new BusinessException (ALREADY_CHECKED );
119+ }
120+
116121 validateParticipantStudyLimit (targetUserId );
117122
118- Alarm alarm = findValidAlarm (alarmId );
123+ Alarm alarm = findValidAlarm (targetUserId , alarmId );
119124 Long studyId = alarm .getDomainId ();
120125 Study study = findValidStudy (studyId );
121126 studyMemberRepository .save (StudyMember .createMember (study , targetUserId ));
122127 alarm .checkAlarm ();
123128 }
124129
125130 @ Transactional
126- public void rejectInvite (Long alarmId ) {
127- Alarm alarm = findValidAlarm (alarmId );
131+ public void rejectInvite (Long targetUserId ,Long alarmId ) {
132+
133+ if (isChecked (targetUserId , alarmId )){
134+ throw new BusinessException (ALREADY_CHECKED );
135+ }
136+
137+ Alarm alarm = findValidAlarm (targetUserId , alarmId );
128138 alarm .checkAlarm ();
129139 }
130140
@@ -248,9 +258,8 @@ public void handleStudyPostCommentEvent(StudyPostCommentEvent event) {
248258 );
249259 }
250260
251- private Alarm findValidAlarm (Long alarmId ) {
252- return alarmRepository .findById (alarmId )
253- .orElseThrow (() -> new NotFoundException (AlarmErrorCode .ALARM_NOT_FOUND ));
261+ private Alarm findValidAlarm (Long targetUserId , Long alarmId ) {
262+ return alarmRepository .findByReceiverUserIdAndId (targetUserId , alarmId ).orElseThrow (() -> new NotFoundException (AlarmErrorCode .ALARM_NOT_FOUND ));
254263 }
255264
256265 private Study findValidStudy (Long studyId ) {
@@ -264,4 +273,8 @@ private void validateParticipantStudyLimit(Long userId) {
264273 throw new BusinessException (APPLICATION_PARTICIPANT_LIMIT_EXCEEDED );
265274 }
266275 }
276+
277+ private boolean isChecked (Long targetUserId , Long alarmId ) {
278+ return findValidAlarm (targetUserId , alarmId ).isChecked ();
279+ }
267280}
0 commit comments