Skip to content

Commit

Permalink
Merge pull request #74 from mju-likelion/feature/introduce-length-che…
Browse files Browse the repository at this point in the history
…ck-#73

Feature/#73 자기소개서 제출 시 글자수 검사 추가
  • Loading branch information
Dh3356 authored Feb 24, 2024
2 parents 54c93b7 + 7449c1e commit 2cd9138
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/main/java/org/mjulikelion/bagel/errorcode/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public enum ErrorCode {
INVALID_INTRODUCE_ERROR("4003", "유효하지 않은 자기소개 항목 입니다."),//유효하지 않은 자기소개 항목
INVALID_AGREEMENT_ERROR("4004", "유효하지 않은 동의 항목 입니다."),//유효하지 않은 동의 항목
INVALID_INTRODUCE_MISSING_ERROR("4005", "자기소개 항목이 누락되었습니다."),//자기소개 항목이 누락됨
INVALID_AGREEMENT_MISSING_ERROR("4006", "동의 항목이 누락되었습니다.");//동의 항목이 누락됨
INVALID_AGREEMENT_MISSING_ERROR("4006", "동의 항목이 누락되었습니다."),//동의 항목이 누락됨
INVALID_INTRODUCE_LENGTH_ERROR("4007", "자기소개 항목의 길이가 유효하지 않습니다.");//자기소개 항목의 길이가 유효하지 않음


private final String code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ public interface IntroduceRepository extends JpaRepository<Introduce, String> {
List<Introduce> findAllByPartOrderBySequence(Part part);

Long countByPart(Part part);

List<Introduce> findAllByPart(Part part);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import static org.mjulikelion.bagel.errorcode.ErrorCode.APPLICATION_ALREADY_EXISTS_ERROR;
import static org.mjulikelion.bagel.errorcode.ErrorCode.FILE_STORAGE_ERROR;
import static org.mjulikelion.bagel.errorcode.ErrorCode.INVALID_AGREEMENT_MISSING_ERROR;
import static org.mjulikelion.bagel.errorcode.ErrorCode.INVALID_INTRODUCE_LENGTH_ERROR;
import static org.mjulikelion.bagel.errorcode.ErrorCode.INVALID_INTRODUCE_MISSING_ERROR;
import static org.mjulikelion.bagel.errorcode.ErrorCode.INVALID_MAJOR_ERROR;

import java.util.List;
import java.util.stream.IntStream;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.mjulikelion.bagel.dto.request.ApplicationSaveDto;
Expand Down Expand Up @@ -138,9 +140,7 @@ private List<ApplicationAgreement> convertAgreements(ApplicationSaveDto applicat
List<ApplicationAgreement> agreements = this.applicationAgreementConvertor.convertMapToApplicationAgreement(
applicationSaveDto.getAgreements(), application);

if (!this.isValidAgreementsSize(agreements)) {
throw new InvalidDataException(INVALID_AGREEMENT_MISSING_ERROR);
}
this.validateAgreements(agreements);

return agreements;
}
Expand All @@ -157,9 +157,7 @@ private List<ApplicationIntroduce> convertIntroduces(ApplicationSaveDto applicat
List<ApplicationIntroduce> introduces = this.applicationIntroduceConvertor.convertMapToApplicationIntroduce(
applicationSaveDto.getIntroduces(), application);

if (!this.isValidIntroducesSize(introduces, application.getPart())) {
throw new InvalidDataException(INVALID_INTRODUCE_MISSING_ERROR);
}
this.validateIntroduces(introduces, application.getPart());

return introduces;
}
Expand All @@ -174,6 +172,12 @@ private boolean isValidAgreementsSize(List<ApplicationAgreement> agreements) {
return this.agreementRepository.count() == agreements.size();
}

private void validateAgreements(List<ApplicationAgreement> agreements) {
if (!isValidAgreementsSize(agreements)) {
throw new InvalidDataException(INVALID_AGREEMENT_MISSING_ERROR);
}
}

/**
* 지원서 자기소개 리스트의 누락 여부를 검사.
*
Expand All @@ -185,6 +189,38 @@ private boolean isValidIntroducesSize(List<ApplicationIntroduce> introduces, Par
return introduces.size() == this.introduceRepository.countByPart(part);
}

/**
* 지원서 자기소개의 글자수를 검사.
*
* @param introduces 지원서 자기소개 리스트
* @param part 지원 파트
* @return 유효한 경우 true, 그렇지 않은 경우 false
*/
private boolean isValidIntroducesLength(List<ApplicationIntroduce> introduces, Part part) {
//introduce의 아이디를 DB에 있는 introduce의 아이디와 비교해서 글자수가 맞는지 확인
introduces.forEach(introduce -> log.info(String.valueOf(introduce.getContent().length())));
this.introduceRepository.findAllByPart(part)
.forEach(introduce -> log.info(String.valueOf(introduce.getMaxLength())));
return IntStream.range(0, introduces.size())
.allMatch(i -> introduces.get(i).getContent().length() <= this.introduceRepository.findById(
introduces.get(i).getIntroduce().getId()).orElseThrow().getMaxLength());
}

/**
* 지원서 자기소개의 유효성을 검사.
*
* @param introduces 지원서 자기소개 리스트
* @param part 지원 파트
*/
private void validateIntroduces(List<ApplicationIntroduce> introduces, Part part) {
if (!isValidIntroducesSize(introduces, part)) {
throw new InvalidDataException(INVALID_INTRODUCE_MISSING_ERROR);
}
if (!isValidIntroducesLength(introduces, part)) {
throw new InvalidDataException(INVALID_INTRODUCE_LENGTH_ERROR);
}
}

/**
* 지원서, 동의 항목, 자기소개를 저장.
*
Expand Down

0 comments on commit 2cd9138

Please sign in to comment.