Skip to content

Commit e787cde

Browse files
committed
[EA3-168] refactor: 에러코드 수정
1 parent b17df69 commit e787cde

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

src/main/java/grep/neogulcoder/domain/study/exception/code/StudyErrorCode.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,19 @@ public enum StudyErrorCode implements ErrorCode {
1313

1414
STUDY_CREATE_LIMIT_EXCEEDED("S004", HttpStatus.BAD_REQUEST, "종료되지 않은 스터디는 최대 10개까지만 생성할 수 있습니다."),
1515
STUDY_PARTICIPATE_LIMIT ("S005", HttpStatus.BAD_REQUEST, "종료되지 않은 스터디는 최대 10개까지만 참여할 수 있습니다."),
16-
STUDY_ALREADY_STARTED("S006", HttpStatus.BAD_REQUEST, "이미 시작된 스터디의 시작일은 변경할 수 없습니다."),
17-
STUDY_DELETE_NOT_ALLOWED("S007", HttpStatus.BAD_REQUEST, "스터디 멤버가 1명일 때만 삭제할 수 있습니다."),
18-
STUDY_LOCATION_REQUIRED("S008", HttpStatus.BAD_REQUEST, "스터디 타입이 OFFLINE이나 HYBRID인 스터디는 지역 입력이 필수입니다."),
19-
20-
STUDY_EXTENSION_NOT_AVAILABLE("S009", HttpStatus.BAD_REQUEST, "스터디 연장은 스터디 종료일 7일 전부터 가능합니다."),
21-
END_DATE_BEFORE_ORIGIN_STUDY("S010", HttpStatus.BAD_REQUEST, "연장 스터디 종료일은 기존 스터디 종료일 이후여야 합니다."),
22-
ALREADY_EXTENDED_STUDY("S011", HttpStatus.BAD_REQUEST, "이미 연장된 스터디입니다."),
23-
ALREADY_REGISTERED_PARTICIPATION("S012", HttpStatus.BAD_REQUEST, "연장 스터디 참여는 한 번만 등록할 수 있습니다."),
24-
25-
NOT_STUDY_LEADER("S013", HttpStatus.FORBIDDEN, "스터디장만 접근이 가능합니다."),
26-
LEADER_CANNOT_LEAVE_STUDY("S014", HttpStatus.BAD_REQUEST, "스터디장은 스터디를 탈퇴할 수 없습니다."),
27-
LEADER_CANNOT_DELEGATE_TO_SELF("S015", HttpStatus.BAD_REQUEST, "자기 자신에게는 스터디장 위임이 불가능합니다.");
16+
STUDY_PARTICIPANT_LIMIT_EXCEEDED ("S006", HttpStatus.BAD_REQUEST, "해당 사용자가 이미 10개의 스터디에 참여 중입니다."),
17+
STUDY_ALREADY_STARTED("S007", HttpStatus.BAD_REQUEST, "이미 시작된 스터디의 시작일은 변경할 수 없습니다."),
18+
STUDY_DELETE_NOT_ALLOWED("S008", HttpStatus.BAD_REQUEST, "스터디 멤버가 1명일 때만 삭제할 수 있습니다."),
19+
STUDY_LOCATION_REQUIRED("S009", HttpStatus.BAD_REQUEST, "스터디 타입이 OFFLINE이나 HYBRID인 스터디는 지역 입력이 필수입니다."),
20+
21+
STUDY_EXTENSION_NOT_AVAILABLE("S010", HttpStatus.BAD_REQUEST, "스터디 연장은 스터디 종료일 7일 전부터 가능합니다."),
22+
END_DATE_BEFORE_ORIGIN_STUDY("S011", HttpStatus.BAD_REQUEST, "연장 스터디 종료일은 기존 스터디 종료일 이후여야 합니다."),
23+
ALREADY_EXTENDED_STUDY("S012", HttpStatus.BAD_REQUEST, "이미 연장된 스터디입니다."),
24+
ALREADY_REGISTERED_PARTICIPATION("S013", HttpStatus.BAD_REQUEST, "연장 스터디 참여는 한 번만 등록할 수 있습니다."),
25+
26+
NOT_STUDY_LEADER("S014", HttpStatus.FORBIDDEN, "스터디장만 접근이 가능합니다."),
27+
LEADER_CANNOT_LEAVE_STUDY("S015", HttpStatus.BAD_REQUEST, "스터디장은 스터디를 탈퇴할 수 없습니다."),
28+
LEADER_CANNOT_DELEGATE_TO_SELF("S016", HttpStatus.BAD_REQUEST, "자기 자신에게는 스터디장 위임이 불가능합니다.");
2829

2930
private final String code;
3031
private final HttpStatus status;

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@
2525
import org.springframework.stereotype.Service;
2626
import org.springframework.transaction.annotation.Transactional;
2727

28-
import static grep.neogulcoder.domain.recruitment.RecruitmentErrorCode.NOT_FOUND;
29-
import static grep.neogulcoder.domain.recruitment.RecruitmentErrorCode.NOT_OWNER;
30-
import static grep.neogulcoder.domain.study.exception.code.StudyErrorCode.STUDY_NOT_FOUND;
31-
import static grep.neogulcoder.domain.study.exception.code.StudyErrorCode.STUDY_PARTICIPATE_LIMIT;
28+
import static grep.neogulcoder.domain.recruitment.RecruitmentErrorCode.*;
29+
import static grep.neogulcoder.domain.study.exception.code.StudyErrorCode.*;
3230
import static grep.neogulcoder.domain.studyapplication.exception.code.ApplicationErrorCode.*;
3331

3432
@Transactional(readOnly = true)
@@ -65,7 +63,7 @@ public Long createApplication(Long recruitmentPostId, ApplicationCreateRequest r
6563

6664
validateNotLeaderApply(recruitmentPost, userId);
6765
validateNotAlreadyApplied(recruitmentPostId, userId);
68-
validateStudyParticipationLimit(userId);
66+
validateApplicantStudyLimit(userId);
6967

7068
StudyApplication application = request.toEntity(recruitmentPostId, userId);
7169
applicationRepository.save(application);
@@ -81,7 +79,7 @@ public void approveApplication(Long applicationId, Long userId) {
8179

8280
validateOnlyLeaderCanApprove(study, userId);
8381
validateStatusIsApplying(application);
84-
validateStudyParticipationLimit(application.getUserId());
82+
validateParticipantStudyLimit(application.getUserId());
8583

8684
application.approve();
8785

@@ -160,10 +158,17 @@ private void validateOnlyLeaderCanReject(Study study, Long userId) {
160158
}
161159
}
162160

163-
private void validateStudyParticipationLimit(Long userId) {
161+
private void validateApplicantStudyLimit(Long userId) {
164162
int count = studyMemberQueryRepository.countActiveUnfinishedStudies(userId);
165163
if (count >= 10) {
166164
throw new BusinessException(STUDY_PARTICIPATE_LIMIT);
167165
}
168166
}
167+
168+
private void validateParticipantStudyLimit(Long userId) {
169+
int count = studyMemberQueryRepository.countActiveUnfinishedStudies(userId);
170+
if (count >= 10) {
171+
throw new BusinessException(STUDY_PARTICIPANT_LIMIT_EXCEEDED);
172+
}
173+
}
169174
}

0 commit comments

Comments
 (0)