Skip to content

Commit 9f47294

Browse files
committed
feature: 스터디 초대 수락 시 스터디 참여 제한에 걸리면 예외 발생하도록 기능 구현
1 parent 13e721b commit 9f47294

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/main/java/grep/neogulcoder/domain/alram/service/AlarmService.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
import grep.neogulcoder.domain.study.Study;
1010
import grep.neogulcoder.domain.study.StudyMember;
1111
import grep.neogulcoder.domain.study.event.StudyInviteEvent;
12+
import grep.neogulcoder.domain.study.repository.StudyMemberQueryRepository;
1213
import grep.neogulcoder.domain.study.repository.StudyRepository;
14+
import grep.neogulcoder.global.exception.business.BusinessException;
1315
import grep.neogulcoder.global.exception.business.NotFoundException;
1416
import grep.neogulcoder.global.provider.finder.MessageFinder;
1517
import java.util.List;
@@ -19,6 +21,7 @@
1921
import org.springframework.transaction.annotation.Transactional;
2022

2123
import 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
}

src/main/java/grep/neogulcoder/domain/study/service/StudyService.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,6 @@ public void deleteStudy(Long studyId, Long userId) {
174174
recruitmentPostRepository.deactivateByStudyId(studyId);
175175
}
176176

177-
@Transactional
178-
public void deleteStudyByAdmin(Long studyId) {
179-
Study study = findValidStudy(studyId);
180-
181-
study.delete();
182-
}
183-
184177
private Study findValidStudy(Long studyId) {
185178
return studyRepository.findById(studyId)
186179
.orElseThrow(() -> new NotFoundException(STUDY_NOT_FOUND));

0 commit comments

Comments
 (0)