Skip to content

Commit ff8d0a4

Browse files
sukangpunchwhqtker
authored andcommitted
feat: 멘토 승격 요청 횟수 제한 추가 (#720)
유저당 멘토 승격 요청을 최대 5회까지만 가능하도록 제한
1 parent ed59864 commit ff8d0a4

3 files changed

Lines changed: 32 additions & 0 deletions

File tree

src/main/java/com/example/solidconnection/common/exception/ErrorCode.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.example.solidconnection.common.exception;
22

33
import static com.example.solidconnection.application.service.ApplicationSubmissionService.APPLICATION_UPDATE_COUNT_LIMIT;
4+
import static com.example.solidconnection.mentor.service.MentorApplicationService.MENTOR_APPLICATION_COUNT_LIMIT;
45
import static com.example.solidconnection.siteuser.service.MyPageService.MIN_DAYS_BETWEEN_NICKNAME_CHANGES;
56

67
import lombok.AllArgsConstructor;
@@ -133,6 +134,7 @@ public enum ErrorCode {
133134
UNAUTHORIZED_MENTORING(HttpStatus.FORBIDDEN.value(), "멘토링 권한이 없습니다."),
134135
MENTORING_ALREADY_CONFIRMED(HttpStatus.BAD_REQUEST.value(), "이미 승인 또는 거절된 멘토링입니다."),
135136
MENTOR_APPLICATION_ALREADY_EXISTED(HttpStatus.CONFLICT.value(), "멘토 승격 요청이 이미 존재합니다."),
137+
MENTOR_APPLICATION_LIMIT_EXCEEDED(HttpStatus.BAD_REQUEST.value(), "멘토 승격 요청은 " + MENTOR_APPLICATION_COUNT_LIMIT + "회까지만 가능합니다."),
136138
INVALID_EXCHANGE_STATUS_FOR_MENTOR(HttpStatus.BAD_REQUEST.value(), "멘토 승격 지원 가능한 교환학생 상태가 아닙니다."),
137139
UNIVERSITY_ID_REQUIRED_FOR_CATALOG(HttpStatus.BAD_REQUEST.value(), "목록에서 학교를 선택한 경우 학교 정보가 필요합니다."),
138140
UNIVERSITY_ID_MUST_BE_NULL_FOR_OTHER(HttpStatus.BAD_REQUEST.value(), "기타 학교를 선택한 경우 학교 정보를 입력할 수 없습니다."),

src/main/java/com/example/solidconnection/mentor/service/MentorApplicationService.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.example.solidconnection.mentor.service;
22

33
import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_APPLICATION_ALREADY_EXISTED;
4+
import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_APPLICATION_LIMIT_EXCEEDED;
45
import static com.example.solidconnection.common.exception.ErrorCode.TERM_NOT_FOUND;
56
import static com.example.solidconnection.common.exception.ErrorCode.USER_NOT_FOUND;
67

@@ -28,6 +29,8 @@
2829
@Slf4j
2930
public class MentorApplicationService {
3031

32+
public static final int MENTOR_APPLICATION_COUNT_LIMIT = 5;
33+
3134
private final MentorApplicationRepository mentorApplicationRepository;
3235
private final SiteUserRepository siteUserRepository;
3336
private final S3Service s3Service;
@@ -40,6 +43,7 @@ public void submitMentorApplication(
4043
MultipartFile file
4144
) {
4245
ensureNoPendingOrApprovedMentorApplication(siteUserId);
46+
ensureApplicationCountNotExceeded(siteUserId);
4347

4448
SiteUser siteUser = siteUserRepository.findById(siteUserId)
4549
.orElseThrow(() -> new CustomException(USER_NOT_FOUND));
@@ -66,4 +70,10 @@ private void ensureNoPendingOrApprovedMentorApplication(long siteUserId) {
6670
throw new CustomException(MENTOR_APPLICATION_ALREADY_EXISTED);
6771
}
6872
}
73+
74+
private void ensureApplicationCountNotExceeded(long siteUserId) {
75+
if (mentorApplicationRepository.countBySiteUserId(siteUserId) >= MENTOR_APPLICATION_COUNT_LIMIT) {
76+
throw new CustomException(MENTOR_APPLICATION_LIMIT_EXCEEDED);
77+
}
78+
}
6979
}

src/test/java/com/example/solidconnection/mentor/service/MentorApplicationServiceTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.example.solidconnection.mentor.service;
22

33
import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_APPLICATION_ALREADY_EXISTED;
4+
import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_APPLICATION_LIMIT_EXCEEDED;
45
import static com.example.solidconnection.common.exception.ErrorCode.UNIVERSITY_ID_MUST_BE_NULL_FOR_OTHER;
56
import static com.example.solidconnection.common.exception.ErrorCode.UNIVERSITY_ID_REQUIRED_FOR_CATALOG;
7+
import static com.example.solidconnection.mentor.service.MentorApplicationService.MENTOR_APPLICATION_COUNT_LIMIT;
68
import static org.assertj.core.api.Assertions.assertThat;
79
import static org.assertj.core.api.AssertionsForClassTypes.assertThatCode;
810
import static org.mockito.BDDMockito.given;
@@ -163,6 +165,24 @@ void setUp() {
163165
.hasMessage(MENTOR_APPLICATION_ALREADY_EXISTED.getMessage());
164166
}
165167

168+
@Test
169+
void 멘토_승격_신청_횟수가_최대_횟수에_도달하면_예외가_발생한다() {
170+
// given
171+
for (int i = 0; i < MENTOR_APPLICATION_COUNT_LIMIT; i++) {
172+
mentorApplicationFixture.거절된_멘토신청(user.getId(), UniversitySelectType.CATALOG, 1L);
173+
}
174+
175+
UniversitySelectType universitySelectType = UniversitySelectType.CATALOG;
176+
Long universityId = 1L;
177+
MentorApplicationRequest request = createMentorApplicationRequest(universitySelectType, universityId);
178+
MockMultipartFile file = createMentorProofFile();
179+
180+
// when & then
181+
assertThatCode(() -> mentorApplicationService.submitMentorApplication(user.getId(), request, file))
182+
.isInstanceOf(CustomException.class)
183+
.hasMessage(MENTOR_APPLICATION_LIMIT_EXCEEDED.getMessage());
184+
}
185+
166186
@Test
167187
void 이미_REJECTED_상태인_멘토_승격_요청이_존재할_때_멘토_신청이_등록된다() {
168188
// given

0 commit comments

Comments
 (0)