Skip to content

Commit 6fd062c

Browse files
committed
[EA3-200] refactor: 스터디 참여 제한 로직 수정
1 parent c157a5d commit 6fd062c

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

src/main/java/grep/neogulcoder/domain/study/Study.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public class Study extends BaseEntity {
5050
@Version
5151
private Long version;
5252

53+
private static final int MAX_JOINED_STUDY_COUNT = 10;
54+
5355
protected Study() {
5456
}
5557

@@ -122,4 +124,8 @@ public boolean isReviewableAt(LocalDateTime currentDateTime) {
122124
return (currentDateTime.isEqual(this.endDate) || currentDateTime.isAfter(this.endDate)) &&
123125
(currentDateTime.isEqual(reviewableDateTime) || currentDateTime.isBefore(reviewableDateTime));
124126
}
127+
128+
public static boolean isOverJoinLimit(int joinedStudyCount) {
129+
return joinedStudyCount >= MAX_JOINED_STUDY_COUNT;
130+
}
125131
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
import java.util.List;
4141
import java.util.Optional;
4242

43-
import static grep.neogulcoder.domain.study.enums.StudyMemberRole.LEADER;
43+
import static grep.neogulcoder.domain.study.enums.StudyMemberRole.*;
4444
import static grep.neogulcoder.domain.study.exception.code.StudyErrorCode.*;
45-
import static grep.neogulcoder.domain.users.exception.code.UserErrorCode.USER_NOT_FOUND;
45+
import static grep.neogulcoder.domain.users.exception.code.UserErrorCode.*;
4646

4747
@Transactional(readOnly = true)
4848
@RequiredArgsConstructor
@@ -184,8 +184,8 @@ private StudyMember getStudyMemberById(Long studyId, Long userId) {
184184
}
185185

186186
private void validateStudyCreateLimit(Long userId) {
187-
int count = studyRepository.countByUserIdAndActivatedTrueAndFinishedFalse(userId);
188-
if (count >= 10) {
187+
int joinedStudyCount = studyRepository.countByUserIdAndActivatedTrueAndFinishedFalse(userId);
188+
if (Study.isOverJoinLimit(joinedStudyCount)) {
189189
throw new BusinessException(STUDY_CREATE_LIMIT_EXCEEDED);
190190
}
191191
}

src/main/java/grep/neogulcoder/domain/studyapplication/service/ApplicationService.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,15 @@ private void validateOnlyLeaderCanReject(Study study, Long userId) {
170170
}
171171

172172
private void validateApplicantStudyLimit(Long userId) {
173-
int count = studyMemberQueryRepository.countActiveUnfinishedStudies(userId);
174-
if (count >= 10) {
173+
int joinedStudyCount = studyMemberQueryRepository.countActiveUnfinishedStudies(userId);
174+
if (Study.isOverJoinLimit(joinedStudyCount)) {
175175
throw new BusinessException(APPLICATION_PARTICIPATION_LIMIT_EXCEEDED);
176176
}
177177
}
178178

179179
private void validateParticipantStudyLimit(Long userId) {
180-
int count = studyMemberQueryRepository.countActiveUnfinishedStudies(userId);
181-
if (count >= 10) {
180+
int joinedStudyCount = studyMemberQueryRepository.countActiveUnfinishedStudies(userId);
181+
if (Study.isOverJoinLimit(joinedStudyCount)) {
182182
throw new BusinessException(APPLICATION_PARTICIPANT_LIMIT_EXCEEDED);
183183
}
184184
}

0 commit comments

Comments
 (0)