Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.solidconnection.common.exception;

import static com.example.solidconnection.application.service.ApplicationSubmissionService.APPLICATION_UPDATE_COUNT_LIMIT;
import static com.example.solidconnection.mentor.service.MentorApplicationService.MENTOR_APPLICATION_COUNT_LIMIT;
import static com.example.solidconnection.siteuser.service.MyPageService.MIN_DAYS_BETWEEN_NICKNAME_CHANGES;

import lombok.AllArgsConstructor;
Expand Down Expand Up @@ -133,6 +134,7 @@ public enum ErrorCode {
UNAUTHORIZED_MENTORING(HttpStatus.FORBIDDEN.value(), "멘토링 권한이 없습니다."),
MENTORING_ALREADY_CONFIRMED(HttpStatus.BAD_REQUEST.value(), "이미 승인 또는 거절된 멘토링입니다."),
MENTOR_APPLICATION_ALREADY_EXISTED(HttpStatus.CONFLICT.value(), "멘토 승격 요청이 이미 존재합니다."),
MENTOR_APPLICATION_LIMIT_EXCEEDED(HttpStatus.BAD_REQUEST.value(), "멘토 승격 요청은 " + MENTOR_APPLICATION_COUNT_LIMIT + "회까지만 가능합니다."),
INVALID_EXCHANGE_STATUS_FOR_MENTOR(HttpStatus.BAD_REQUEST.value(), "멘토 승격 지원 가능한 교환학생 상태가 아닙니다."),
UNIVERSITY_ID_REQUIRED_FOR_CATALOG(HttpStatus.BAD_REQUEST.value(), "목록에서 학교를 선택한 경우 학교 정보가 필요합니다."),
UNIVERSITY_ID_MUST_BE_NULL_FOR_OTHER(HttpStatus.BAD_REQUEST.value(), "기타 학교를 선택한 경우 학교 정보를 입력할 수 없습니다."),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.solidconnection.mentor.service;

import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_APPLICATION_ALREADY_EXISTED;
import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_APPLICATION_LIMIT_EXCEEDED;
import static com.example.solidconnection.common.exception.ErrorCode.TERM_NOT_FOUND;
import static com.example.solidconnection.common.exception.ErrorCode.USER_NOT_FOUND;

Expand Down Expand Up @@ -28,6 +29,8 @@
@Slf4j
public class MentorApplicationService {

public static final int MENTOR_APPLICATION_COUNT_LIMIT = 5;

private final MentorApplicationRepository mentorApplicationRepository;
private final SiteUserRepository siteUserRepository;
private final S3Service s3Service;
Expand All @@ -40,6 +43,7 @@ public void submitMentorApplication(
MultipartFile file
) {
ensureNoPendingOrApprovedMentorApplication(siteUserId);
ensureApplicationCountNotExceeded(siteUserId);

SiteUser siteUser = siteUserRepository.findById(siteUserId)
.orElseThrow(() -> new CustomException(USER_NOT_FOUND));
Expand All @@ -66,4 +70,10 @@ private void ensureNoPendingOrApprovedMentorApplication(long siteUserId) {
throw new CustomException(MENTOR_APPLICATION_ALREADY_EXISTED);
}
}

private void ensureApplicationCountNotExceeded(long siteUserId) {
if (mentorApplicationRepository.countBySiteUserId(siteUserId) >= MENTOR_APPLICATION_COUNT_LIMIT) {
throw new CustomException(MENTOR_APPLICATION_LIMIT_EXCEEDED);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.example.solidconnection.mentor.service;

import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_APPLICATION_ALREADY_EXISTED;
import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_APPLICATION_LIMIT_EXCEEDED;
import static com.example.solidconnection.common.exception.ErrorCode.UNIVERSITY_ID_MUST_BE_NULL_FOR_OTHER;
import static com.example.solidconnection.common.exception.ErrorCode.UNIVERSITY_ID_REQUIRED_FOR_CATALOG;
import static com.example.solidconnection.mentor.service.MentorApplicationService.MENTOR_APPLICATION_COUNT_LIMIT;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatCode;
import static org.mockito.BDDMockito.given;
Expand Down Expand Up @@ -163,6 +165,24 @@ void setUp() {
.hasMessage(MENTOR_APPLICATION_ALREADY_EXISTED.getMessage());
}

@Test
void 멘토_승격_신청_횟수가_최대_횟수에_도달하면_예외가_발생한다() {
// given
for (int i = 0; i < MENTOR_APPLICATION_COUNT_LIMIT; i++) {
mentorApplicationFixture.거절된_멘토신청(user.getId(), UniversitySelectType.CATALOG, 1L);
}

UniversitySelectType universitySelectType = UniversitySelectType.CATALOG;
Long universityId = 1L;
MentorApplicationRequest request = createMentorApplicationRequest(universitySelectType, universityId);
MockMultipartFile file = createMentorProofFile();

// when & then
assertThatCode(() -> mentorApplicationService.submitMentorApplication(user.getId(), request, file))
.isInstanceOf(CustomException.class)
.hasMessage(MENTOR_APPLICATION_LIMIT_EXCEEDED.getMessage());
}

@Test
void 이미_REJECTED_상태인_멘토_승격_요청이_존재할_때_멘토_신청이_등록된다() {
// given
Expand Down
Loading