Skip to content
Merged
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
Expand Up @@ -54,6 +54,9 @@ public class Application {
@ManyToOne
private UniversityInfoForApply secondChoiceUniversity;

@ManyToOne
private UniversityInfoForApply thirdChoiceUniversity;

@ManyToOne
private SiteUser siteUser;

Expand All @@ -77,12 +80,14 @@ public void updateGpaAndLanguageTest(
public void updateUniversityChoice(
UniversityInfoForApply firstChoiceUniversity,
UniversityInfoForApply secondChoiceUniversity,
UniversityInfoForApply thirdChoiceUniversity,
String nicknameForApply) {
if (this.firstChoiceUniversity != null) {
this.updateCount++;
}
this.firstChoiceUniversity = firstChoiceUniversity;
this.secondChoiceUniversity = secondChoiceUniversity;
this.thirdChoiceUniversity = thirdChoiceUniversity;
this.nicknameForApply = nicknameForApply;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ public record ApplicationsResponse(
List<UniversityApplicantsResponse> firstChoice,

@ArraySchema(arraySchema = @Schema(description = "2지망 대학에 지원한 지원자 목록"))
List<UniversityApplicantsResponse> secondChoice) {
List<UniversityApplicantsResponse> secondChoice,

@ArraySchema(arraySchema = @Schema(description = "3지망 대학에 지원한 지원자 목록"))
List<UniversityApplicantsResponse> thirdChoice) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ public record UniversityChoiceRequest(
Long firstChoiceUniversityId,

@Schema(description = "2지망 대학교의 지원 정보 ID (선택사항)", example = "2", nullable = true)
Long secondChoiceUniversityId) {
}
Long secondChoiceUniversityId,

@Schema(description = "3지망 대학교의 지원 정보 ID (선택사항)", example = "3", nullable = true)
Long thirdChoiceUniversityId) {}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public interface ApplicationRepository extends JpaRepository<Application, Long>

List<Application> findAllBySecondChoiceUniversityAndVerifyStatus(UniversityInfoForApply secondChoiceUniversity, VerifyStatus verifyStatus);

List<Application> findAllByThirdChoiceUniversityAndVerifyStatus(UniversityInfoForApply thirdChoiceUniversity, VerifyStatus verifyStatus);

default Application getApplicationBySiteUser(SiteUser siteUser) {
return findBySiteUser(siteUser)
.orElseThrow(() -> new CustomException(APPLICATION_NOT_FOUND));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public ApplicationsResponse getApplicants(String email, String regionCode, Strin
// 1지망, 2지망 지원자들을 조회한다.
List<UniversityApplicantsResponse> firstChoiceApplicants = getFirstChoiceApplicants(universities, siteUser);
List<UniversityApplicantsResponse> secondChoiceApplicants = getSecondChoiceApplicants(universities, siteUser);
return new ApplicationsResponse(firstChoiceApplicants, secondChoiceApplicants);
List <UniversityApplicantsResponse> thirdChoiceApplicants = getThirdChoiceApplicants(universities, siteUser);
return new ApplicationsResponse(firstChoiceApplicants, secondChoiceApplicants, thirdChoiceApplicants);
}

private void validateSiteUserCanViewApplicants(SiteUser siteUser) {
Expand All @@ -81,6 +82,14 @@ private List<UniversityApplicantsResponse> getSecondChoiceApplicants(List<Univer
);
}

private List<UniversityApplicantsResponse> getThirdChoiceApplicants(List<University> universities, SiteUser siteUser) {
return getApplicantsByChoice(
universities,
siteUser,
uia -> applicationRepository.findAllByThirdChoiceUniversityAndVerifyStatus(uia, VerifyStatus.APPROVED)
);
}

private List<UniversityApplicantsResponse> getApplicantsByChoice(
List<University> searchedUniversities,
SiteUser siteUser,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashSet;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍👍

import java.util.Objects;
import java.util.Set;

import static com.example.solidconnection.custom.exception.ErrorCode.APPLY_UPDATE_LIMIT_EXCEED;
import static com.example.solidconnection.custom.exception.ErrorCode.CANT_APPLY_FOR_SAME_UNIVERSITY;
Expand Down Expand Up @@ -61,7 +63,7 @@ public boolean submitScore(String email, ScoreRequest scoreRequest) {

/*
* 지망 대학교를 제출한다.
* - 첫번째 지망과 두번째 지망이 같은지 검증한다.
* - 지망 대학중 중복된 대학교가 있는지 검증한다.
* - 지원 정보 제출 내역이 없다면, 지금의 프로세스(성적 제출 후 지망대학 제출)에 벗어나는 요청이므로 예외를 응답한다.
* - 기존에 제출한 적이 있다면, 수정한다.
* - 수정 횟수 제한을 초과하지 않았는지 검증한다.
Expand All @@ -70,17 +72,19 @@ public boolean submitScore(String email, ScoreRequest scoreRequest) {
* */
@Transactional
public boolean submitUniversityChoice(String email, UniversityChoiceRequest universityChoiceRequest) {
validateFirstAndSecondChoiceIdDifferent(universityChoiceRequest);
validateNoDuplicateUniversityChoices(universityChoiceRequest);
Application application = applicationRepository.findBySiteUser_Email(email)
.orElseThrow(() -> new CustomException(SCORE_SHOULD_SUBMITTED_FIRST));

UniversityInfoForApply firstChoiceUniversity = universityInfoForApplyRepository
.getUniversityInfoForApplyByIdAndTerm(universityChoiceRequest.firstChoiceUniversityId(), term);
UniversityInfoForApply secondChoiceUniversity = universityInfoForApplyRepository
.getUniversityInfoForApplyByIdAndTerm(universityChoiceRequest.secondChoiceUniversityId(), term);
UniversityInfoForApply thirdChoiceUniversity = universityInfoForApplyRepository
.getUniversityInfoForApplyByIdAndTerm(universityChoiceRequest.thirdChoiceUniversityId(), term);

validateUpdateLimitNotExceed(application);
application.updateUniversityChoice(firstChoiceUniversity, secondChoiceUniversity, getRandomNickname());
application.updateUniversityChoice(firstChoiceUniversity, secondChoiceUniversity, thirdChoiceUniversity, getRandomNickname());
return true;
}

Expand All @@ -98,10 +102,14 @@ private void validateUpdateLimitNotExceed(Application application) {
}
}

private void validateFirstAndSecondChoiceIdDifferent(UniversityChoiceRequest universityChoiceRequest) {
if (Objects.equals(
universityChoiceRequest.firstChoiceUniversityId(),
universityChoiceRequest.secondChoiceUniversityId())) {
private void validateNoDuplicateUniversityChoices(UniversityChoiceRequest universityChoiceRequest) {
Set<Long> uniqueUniversityIds = new HashSet<>();

uniqueUniversityIds.add(universityChoiceRequest.firstChoiceUniversityId());
uniqueUniversityIds.add(universityChoiceRequest.secondChoiceUniversityId());
uniqueUniversityIds.add(universityChoiceRequest.thirdChoiceUniversityId());

if (uniqueUniversityIds.size() < 3) {
throw new CustomException(CANT_APPLY_FOR_SAME_UNIVERSITY);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public enum ErrorCode {
INVALID_TEST_TYPE(HttpStatus.BAD_REQUEST.value(), "지원하지 않은 어학 시험 종류입니다."),
APPLICATION_NOT_APPROVED(HttpStatus.BAD_REQUEST.value(), "성적표가 인증되지 않았습니다."),
APPLY_UPDATE_LIMIT_EXCEED(HttpStatus.BAD_REQUEST.value(), "지원 정보 수정은 " + APPLICATION_UPDATE_COUNT_LIMIT + "회까지만 가능합니다."),
CANT_APPLY_FOR_SAME_UNIVERSITY(HttpStatus.BAD_REQUEST.value(), "1, 2지망에 동일한 대학교를 입력할 수 없습니다."),
CANT_APPLY_FOR_SAME_UNIVERSITY(HttpStatus.BAD_REQUEST.value(), "1, 2, 3지망에 동일한 대학교를 입력할 수 없습니다."),
CAN_NOT_CHANGE_NICKNAME_YET(HttpStatus.BAD_REQUEST.value(), "마지막 닉네임 변경으로부터 " + MIN_DAYS_BETWEEN_NICKNAME_CHANGES + "일이 지나지 않았습니다."),

// community
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ public void setUpUserAndToken() {
사용자1_지원정보 = new Application(사용자1, gpa, languageTest);
사용자2_지원정보 = new Application(사용자2, gpa, languageTest);
사용자3_지원정보 = new Application(사용자3, gpa, languageTest);
나의_지원정보.updateUniversityChoice(괌대학_B_지원_정보, 괌대학_A_지원_정보, "0");
사용자1_지원정보.updateUniversityChoice(괌대학_A_지원_정보, 괌대학_B_지원_정보, "1");
사용자2_지원정보.updateUniversityChoice(메이지대학_지원_정보, 그라츠대학_지원_정보, "2");
사용자3_지원정보.updateUniversityChoice(네바다주립대학_라스베이거스_지원_정보, 그라츠공과대학_지원_정보, "3");
나의_지원정보.updateUniversityChoice(괌대학_B_지원_정보, 괌대학_A_지원_정보, 린츠_카톨릭대학_지원_정보, "0");
사용자1_지원정보.updateUniversityChoice(괌대학_A_지원_정보, 괌대학_B_지원_정보, 그라츠공과대학_지원_정보, "1");
사용자2_지원정보.updateUniversityChoice(메이지대학_지원_정보, 그라츠대학_지원_정보, 서던덴마크대학교_지원_정보, "2");
사용자3_지원정보.updateUniversityChoice(네바다주립대학_라스베이거스_지원_정보, 그라츠공과대학_지원_정보, 메이지대학_지원_정보, "3");
나의_지원정보.setVerifyStatus(VerifyStatus.APPROVED);
사용자1_지원정보.setVerifyStatus(VerifyStatus.APPROVED);
사용자2_지원정보.setVerifyStatus(VerifyStatus.APPROVED);
Expand All @@ -89,6 +89,7 @@ public void setUpUserAndToken() {

List<UniversityApplicantsResponse> firstChoiceApplicants = response.firstChoice();
List<UniversityApplicantsResponse> secondChoiceApplicants = response.secondChoice();
List<UniversityApplicantsResponse> thirdChoiceApplicants = response.thirdChoice();

assertThat(firstChoiceApplicants).containsAnyElementsOf(List.of(
UniversityApplicantsResponse.of(괌대학_A_지원_정보,
Expand All @@ -110,6 +111,16 @@ public void setUpUserAndToken() {
UniversityApplicantsResponse.of(그라츠대학_지원_정보,
List.of(ApplicantResponse.of(사용자2_지원정보, false)))
));
assertThat(thirdChoiceApplicants).containsAnyElementsOf(List.of(
UniversityApplicantsResponse.of(린츠_카톨릭대학_지원_정보,
List.of(ApplicantResponse.of(나의_지원정보, true))),
UniversityApplicantsResponse.of(서던덴마크대학교_지원_정보,
List.of(ApplicantResponse.of(사용자2_지원정보, false))),
UniversityApplicantsResponse.of(그라츠공과대학_지원_정보,
List.of(ApplicantResponse.of(사용자1_지원정보, false))),
UniversityApplicantsResponse.of(메이지대학_지원_정보,
List.of(ApplicantResponse.of(사용자3_지원정보, false)))
));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void setUpUserAndToken() {
applicationRepository.save(new Application(siteUser, firstRequest.toGpa(), firstRequest.toLanguageTest()));

// request - body 생성 및 요청
UniversityChoiceRequest request = new UniversityChoiceRequest(그라츠대학_지원_정보.getId(), 코펜하겐IT대학_지원_정보.getId());
UniversityChoiceRequest request = new UniversityChoiceRequest(그라츠대학_지원_정보.getId(), 코펜하겐IT대학_지원_정보.getId(), 메이지대학_지원_정보.getId());
RestAssured.given()
.header("Authorization", "Bearer " + accessToken)
.body(request)
Expand All @@ -135,6 +135,7 @@ public void setUpUserAndToken() {
() -> assertThat(application.getSiteUser().getId()).isEqualTo(siteUser.getId()),
() -> assertThat(application.getFirstChoiceUniversity().getId()).isEqualTo(request.firstChoiceUniversityId()),
() -> assertThat(application.getSecondChoiceUniversity().getId()).isEqualTo(request.secondChoiceUniversityId()),
() -> assertThat(application.getThirdChoiceUniversity().getId()).isEqualTo(request.thirdChoiceUniversityId()),
() -> assertThat(application.getNicknameForApply()).isNotNull(),
() -> assertThat(application.getVerifyStatus()).isEqualTo(VerifyStatus.PENDING),
() -> assertThat(application.getUpdateCount()).isZero());
Expand All @@ -146,11 +147,11 @@ public void setUpUserAndToken() {
ScoreRequest firstRequest = new ScoreRequest(LanguageTestType.TOEFL_IBT, "80",
"languageTestReportUrl", 4.0, 4.5, "gpaReportUrl");
applicationRepository.save(new Application(siteUser, firstRequest.toGpa(), firstRequest.toLanguageTest()))
.updateUniversityChoice(괌대학_A_지원_정보, 괌대학_B_지원_정보, "nickname");
.updateUniversityChoice(괌대학_A_지원_정보, 괌대학_B_지원_정보, 네바다주립대학_라스베이거스_지원_정보, "nickname");
Application initialApplication = applicationRepository.getApplicationBySiteUser(siteUser);

// request - body 생성 및 요청
UniversityChoiceRequest request = new UniversityChoiceRequest(그라츠대학_지원_정보.getId(), 코펜하겐IT대학_지원_정보.getId());
UniversityChoiceRequest request = new UniversityChoiceRequest(그라츠대학_지원_정보.getId(), 코펜하겐IT대학_지원_정보.getId(), 메이지대학_지원_정보.getId());
RestAssured.given()
.header("Authorization", "Bearer " + accessToken)
.body(request)
Expand All @@ -166,6 +167,7 @@ public void setUpUserAndToken() {
() -> assertThat(updatedApplication.getSiteUser().getId()).isEqualTo(siteUser.getId()),
() -> assertThat(updatedApplication.getFirstChoiceUniversity().getId()).isEqualTo(request.firstChoiceUniversityId()),
() -> assertThat(updatedApplication.getSecondChoiceUniversity().getId()).isEqualTo(request.secondChoiceUniversityId()),
() -> assertThat(updatedApplication.getThirdChoiceUniversity().getId()).isEqualTo(request.thirdChoiceUniversityId()),
() -> assertThat(updatedApplication.getNicknameForApply()).isNotNull(),
() -> assertThat(updatedApplication.getVerifyStatus()).isEqualTo(initialApplication.getVerifyStatus()),
() -> assertThat(updatedApplication.getUpdateCount()).isEqualTo(initialApplication.getUpdateCount()));
Expand All @@ -181,12 +183,12 @@ public void setUpUserAndToken() {

// setUp - 지망 대학을 한계까지 수정
for (int i = 0; i <= APPLICATION_UPDATE_COUNT_LIMIT; i++) {
initialApplication.updateUniversityChoice(괌대학_A_지원_정보, 괌대학_B_지원_정보, "nickname");
initialApplication.updateUniversityChoice(괌대학_A_지원_정보, 괌대학_B_지원_정보, 네바다주립대학_라스베이거스_지원_정보, "nickname");
applicationRepository.save(initialApplication);
}

// request - body 생성 및 요청
UniversityChoiceRequest request = new UniversityChoiceRequest(그라츠대학_지원_정보.getId(), 코펜하겐IT대학_지원_정보.getId());
UniversityChoiceRequest request = new UniversityChoiceRequest(그라츠대학_지원_정보.getId(), 코펜하겐IT대학_지원_정보.getId(), 메이지대학_지원_정보.getId());
ErrorResponse errorResponse = RestAssured.given().log().all()
.header("Authorization", "Bearer " + accessToken)
.body(request)
Expand All @@ -202,7 +204,41 @@ public void setUpUserAndToken() {
@Test
void 일지망_대학과_이지망_대학이_같으면_예외_응답을_반환한다() {
// request - body 생성 및 요청
UniversityChoiceRequest request = new UniversityChoiceRequest(그라츠대학_지원_정보.getId(), 그라츠대학_지원_정보.getId());
UniversityChoiceRequest request = new UniversityChoiceRequest(그라츠대학_지원_정보.getId(), 그라츠대학_지원_정보.getId(), 메이지대학_지원_정보.getId());
ErrorResponse errorResponse = RestAssured.given()
.header("Authorization", "Bearer " + accessToken)
.body(request)
.contentType("application/json")
.log().all()
.post("/application/university")
.then().log().all()
.statusCode(HttpStatus.BAD_REQUEST.value())
.extract().as(ErrorResponse.class);

assertThat(errorResponse.message()).isEqualTo(CANT_APPLY_FOR_SAME_UNIVERSITY.getMessage());
}

@Test
void 일지망_대학과_삼지망_대학이_같으면_예외_응답을_반환한다() {
// request - body 생성 및 요청
UniversityChoiceRequest request = new UniversityChoiceRequest(그라츠대학_지원_정보.getId(), 코펜하겐IT대학_지원_정보.getId(), 그라츠대학_지원_정보.getId());
ErrorResponse errorResponse = RestAssured.given()
.header("Authorization", "Bearer " + accessToken)
.body(request)
.contentType("application/json")
.log().all()
.post("/application/university")
.then().log().all()
.statusCode(HttpStatus.BAD_REQUEST.value())
.extract().as(ErrorResponse.class);

assertThat(errorResponse.message()).isEqualTo(CANT_APPLY_FOR_SAME_UNIVERSITY.getMessage());
}

@Test
void 이지망_대학과_삼지망_대학이_같으면_예외_응답을_반환한다() {
// request - body 생성 및 요청
UniversityChoiceRequest request = new UniversityChoiceRequest(그라츠대학_지원_정보.getId(), 코펜하겐IT대학_지원_정보.getId(), 코펜하겐IT대학_지원_정보.getId());
ErrorResponse errorResponse = RestAssured.given()
.header("Authorization", "Bearer " + accessToken)
.body(request)
Expand Down
Loading