99import grep .neogulcoder .domain .study .Study ;
1010import grep .neogulcoder .domain .study .StudyMember ;
1111import grep .neogulcoder .domain .study .event .StudyInviteEvent ;
12+ import grep .neogulcoder .domain .study .repository .StudyMemberQueryRepository ;
1213import grep .neogulcoder .domain .study .repository .StudyRepository ;
14+ import grep .neogulcoder .global .exception .business .BusinessException ;
1315import grep .neogulcoder .global .exception .business .NotFoundException ;
1416import grep .neogulcoder .global .provider .finder .MessageFinder ;
1517import java .util .List ;
1921import org .springframework .transaction .annotation .Transactional ;
2022
2123import static grep .neogulcoder .domain .study .exception .code .StudyErrorCode .STUDY_NOT_FOUND ;
24+ import static grep .neogulcoder .domain .studyapplication .exception .code .ApplicationErrorCode .APPLICATION_PARTICIPANT_LIMIT_EXCEEDED ;
2225
2326@ Service
2427@ RequiredArgsConstructor
@@ -28,6 +31,7 @@ public class AlarmService {
2831 private final AlarmRepository alarmRepository ;
2932 private final MessageFinder messageFinder ;
3033 private final StudyRepository studyRepository ;
34+ private final StudyMemberQueryRepository studyMemberQueryRepository ;
3135
3236 @ Transactional
3337 public void saveAlarm (Long receiverId , AlarmType alarmType , DomainType domainType , Long domainId ) {
@@ -65,8 +69,11 @@ public void handleStudyInviteEvent(StudyInviteEvent event) {
6569 );
6670 }
6771
68- @ Transactional //TODO 회원이 가입한 스터디 체크 로직 필요
72+ @ Transactional
6973 public void acceptInvite (Long targetUserId , Long alarmId ) {
74+
75+ validateParticipantStudyLimit (targetUserId );
76+
7077 Alarm alarm = findValidAlarm (alarmId );
7178 Long studyId = alarm .getDomainId ();
7279 Study study = findValidStudy (studyId );
@@ -88,4 +95,11 @@ private Study findValidStudy(Long studyId) {
8895 return studyRepository .findById (studyId )
8996 .orElseThrow (() -> new NotFoundException (STUDY_NOT_FOUND ));
9097 }
98+
99+ private void validateParticipantStudyLimit (Long userId ) {
100+ int count = studyMemberQueryRepository .countActiveUnfinishedStudies (userId );
101+ if (count >= 10 ) {
102+ throw new BusinessException (APPLICATION_PARTICIPANT_LIMIT_EXCEEDED );
103+ }
104+ }
91105}
0 commit comments