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 @@ -32,10 +32,10 @@ public ResponseEntity<ApplicationSubmissionResponse> apply(
@AuthorizedUser SiteUser siteUser,
@Valid @RequestBody ApplyRequest applyRequest
) {
boolean result = applicationSubmissionService.apply(siteUser, applyRequest);
ApplicationSubmissionResponse applicationSubmissionResponse = applicationSubmissionService.apply(siteUser, applyRequest);
return ResponseEntity
.status(HttpStatus.OK)
.body(new ApplicationSubmissionResponse(result));
.body(applicationSubmissionResponse);
}

@GetMapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class Application {
@Column(length = 100)
private String nicknameForApply;

@Column(columnDefinition = "int not null default 0")
@Column(columnDefinition = "int not null default 1")
private Integer updateCount;

@Column(length = 50, nullable = false)
Expand Down Expand Up @@ -76,7 +76,7 @@ public Application(
this.gpa = gpa;
this.languageTest = languageTest;
this.term = term;
this.updateCount = 0;
this.updateCount = 1;
this.verifyStatus = PENDING;
}

Expand Down Expand Up @@ -115,7 +115,7 @@ public Application(
this.gpa = gpa;
this.languageTest = languageTest;
this.term = term;
this.updateCount = 0;
this.updateCount = 1;
this.firstChoiceUniversity = firstChoiceUniversity;
this.secondChoiceUniversity = secondChoiceUniversity;
this.thirdChoiceUniversity = thirdChoiceUniversity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.example.solidconnection.application.dto;

import com.example.solidconnection.application.domain.Application;

public record ApplicationSubmissionResponse(
boolean isSuccess) {
int applyCount
) {
public static ApplicationSubmissionResponse from(Application application) {
return new ApplicationSubmissionResponse(application.getUpdateCount());
}
}
Comment on lines 5 to 11
Copy link
Collaborator

Choose a reason for hiding this comment

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

"업데이트 횟수" 반환하는 것 좋네요!
프론트에서 메세지를 주기도 편해보입니다.
다만 api 문서 최신화를 위해서 api docs도 업데이트해주세요~

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Response만 바뀌었는데 Response도 바꾸는 곳이 있나요?

Copy link
Collaborator

Choose a reason for hiding this comment

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

없네요.. 머쓱🫨

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.solidconnection.application.service;

import com.example.solidconnection.application.domain.Application;
import com.example.solidconnection.application.dto.ApplicationSubmissionResponse;
import com.example.solidconnection.application.dto.ApplyRequest;
import com.example.solidconnection.application.dto.UniversityChoiceRequest;
import com.example.solidconnection.application.repository.ApplicationRepository;
Expand Down Expand Up @@ -49,15 +50,10 @@ public class ApplicationSubmissionService {
key = {"applications:all"},
cacheManager = "customCacheManager"
)
public boolean apply(SiteUser siteUser, ApplyRequest applyRequest) {
public ApplicationSubmissionResponse apply(SiteUser siteUser, ApplyRequest applyRequest) {
UniversityChoiceRequest universityChoiceRequest = applyRequest.universityChoiceRequest();

Long gpaScoreId = applyRequest.gpaScoreId();
Long languageTestScoreId = applyRequest.languageTestScoreId();
GpaScore gpaScore = getValidGpaScore(siteUser, gpaScoreId);
LanguageTestScore languageTestScore = getValidLanguageTestScore(siteUser, languageTestScoreId);

Optional<Application> application = applicationRepository.findBySiteUserAndTerm(siteUser, term);
GpaScore gpaScore = getValidGpaScore(siteUser, applyRequest.gpaScoreId());
LanguageTestScore languageTestScore = getValidLanguageTestScore(siteUser, applyRequest.languageTestScoreId());

UniversityInfoForApply firstChoiceUniversity = universityInfoForApplyRepository
.getUniversityInfoForApplyByIdAndTerm(universityChoiceRequest.firstChoiceUniversityId(), term);
Expand All @@ -68,22 +64,19 @@ public boolean apply(SiteUser siteUser, ApplyRequest applyRequest) {
.map(id -> universityInfoForApplyRepository.getUniversityInfoForApplyByIdAndTerm(id, term))
.orElse(null);

if (application.isEmpty()) {
Application newApplication = new Application(siteUser, gpaScore.getGpa(), languageTestScore.getLanguageTest(),
term, firstChoiceUniversity, secondChoiceUniversity, thirdChoiceUniversity, getRandomNickname());
newApplication.setVerifyStatus(VerifyStatus.APPROVED);
applicationRepository.save(newApplication);
} else {
Application before = application.get();
validateUpdateLimitNotExceed(before);
before.setIsDeleteTrue(); // 기존 이력 soft delete 수행한다.

Application newApplication = new Application(siteUser, gpaScore.getGpa(), languageTestScore.getLanguageTest(),
term, before.getUpdateCount() + 1, firstChoiceUniversity, secondChoiceUniversity, thirdChoiceUniversity, getRandomNickname());
newApplication.setVerifyStatus(VerifyStatus.APPROVED);
applicationRepository.save(newApplication);
}
return true;
Optional<Application> existingApplication = applicationRepository.findBySiteUserAndTerm(siteUser, term);
int updateCount = existingApplication
.map(application -> {
validateUpdateLimitNotExceed(application);
application.setIsDeleteTrue();
return application.getUpdateCount() + 1;
})
.orElse(1);
Application newApplication = new Application(siteUser, gpaScore.getGpa(), languageTestScore.getLanguageTest(),
term, updateCount, firstChoiceUniversity, secondChoiceUniversity, thirdChoiceUniversity, getRandomNickname());
newApplication.setVerifyStatus(VerifyStatus.APPROVED);
applicationRepository.save(newApplication);
return ApplicationSubmissionResponse.from(newApplication);
}

private GpaScore getValidGpaScore(SiteUser siteUser, Long gpaScoreId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE application
ALTER COLUMN update_count SET DEFAULT 1;
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.example.solidconnection.application.domain.Application;
import com.example.solidconnection.application.domain.Gpa;
import com.example.solidconnection.application.domain.LanguageTest;
import com.example.solidconnection.application.dto.ApplicationSubmissionResponse;
import com.example.solidconnection.application.dto.ApplyRequest;
import com.example.solidconnection.application.dto.UniversityChoiceRequest;
import com.example.solidconnection.application.repository.ApplicationRepository;
Expand All @@ -21,7 +22,6 @@

import static com.example.solidconnection.application.service.ApplicationSubmissionService.APPLICATION_UPDATE_COUNT_LIMIT;
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;
import static com.example.solidconnection.custom.exception.ErrorCode.INVALID_GPA_SCORE_STATUS;
import static com.example.solidconnection.custom.exception.ErrorCode.INVALID_LANGUAGE_TEST_SCORE_STATUS;
import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -56,17 +56,16 @@ class ApplicationSubmissionServiceTest extends BaseIntegrationTest {
ApplyRequest request = new ApplyRequest(gpaScore.getId(), languageTestScore.getId(), universityChoiceRequest);

// when
boolean result = applicationSubmissionService.apply(테스트유저_1, request);
ApplicationSubmissionResponse response = applicationSubmissionService.apply(테스트유저_1, request);

// then
Application savedApplication = applicationRepository.findBySiteUserAndTerm(테스트유저_1, term).orElseThrow();
assertAll(
() -> assertThat(result).isTrue(),
() -> assertThat(response.applyCount()).isEqualTo(savedApplication.getUpdateCount()),
() -> assertThat(savedApplication.getGpa()).isEqualTo(gpaScore.getGpa()),
() -> assertThat(savedApplication.getLanguageTest()).isEqualTo(languageTestScore.getLanguageTest()),
() -> assertThat(savedApplication.getVerifyStatus()).isEqualTo(VerifyStatus.APPROVED),
() -> assertThat(savedApplication.getNicknameForApply()).isNotNull(),
() -> assertThat(savedApplication.getUpdateCount()).isZero(),
() -> assertThat(savedApplication.getTerm()).isEqualTo(term),
() -> assertThat(savedApplication.isDelete()).isFalse(),
() -> assertThat(savedApplication.getFirstChoiceUniversity().getId()).isEqualTo(괌대학_A_지원_정보.getId()),
Expand Down Expand Up @@ -128,7 +127,7 @@ class ApplicationSubmissionServiceTest extends BaseIntegrationTest {
);
ApplyRequest request = new ApplyRequest(gpaScore.getId(), languageTestScore.getId(), universityChoiceRequest);

for (int i = 0; i < APPLICATION_UPDATE_COUNT_LIMIT + 1; i++) {
for (int i = 0; i < APPLICATION_UPDATE_COUNT_LIMIT; i++) {
applicationSubmissionService.apply(테스트유저_1, request);
}

Expand Down