Skip to content

Commit f653186

Browse files
authored
refactor: 학기를 테이블로 관리하도록 변경 (#526)
* feat: 학기 테이블 추가 * refactor: UnivApplyInfo의 term -> termId로 변경 * refactor: UnivApplyInfoRepository의 term -> termId로 변경 * refactor: UnivApplyInfo 관련 service의 term -> termId로 변경 * refactor: UnivApplyInfo controller term 제거 * feat: Term 관련 fixture 추가 * refactor: UnivApplyInfoFixture의 term -> termId로 변경 * test: UnivApplyInfo 관련 테스트 시 Term fixture 추가 * refactor: Application의 term -> termId로 변경 * refactor: ApplicationRepository의 term -> termId로 변경 * refactor: Application 관련 service의 term -> termId로 변경 * refactor: ApplicationFixture의 term -> termId로 변경 * test: Application 관련 테스트 시 Term fixture 추가 * refactor: Mentor의 term -> termId로 변경 * refactor: Mentor 관련 service의 term -> termId로 변경 * refactor: MentorFixture의 term -> termId로 변경 * test: Mentor 관련 테스트 시 Term fixture 추가 * test: term 관련 yml 제거 * refactor: term 관련 data.sql 추가 * chore: 서브모듈 최신화 * refactor: 코드래빗 반영 * feat: flyway 스크립트 작성 - 수정 필요 * feat: flyway 스크립트 수정 * refactor: 2026-1학기를 제외한 나머지는 is_current를 false로 변경 * refactor: term -> termId 변경 * refactor: Long type으로 변경
1 parent eaaf3b9 commit f653186

File tree

49 files changed

+799
-302
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+799
-302
lines changed

src/main/java/com/example/solidconnection/application/domain/Application.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
@Entity
2929
@Table(indexes = {
3030
@Index(name = "idx_app_user_term_delete",
31-
columnList = "site_user_id, term, is_delete"),
31+
columnList = "site_user_id, term_id, is_delete"),
3232
@Index(name = "idx_app_first_choice_search",
33-
columnList = "verify_status, term, is_delete, first_choice_university_info_for_apply_id"),
33+
columnList = "verify_status, term_id, is_delete, first_choice_university_info_for_apply_id"),
3434
@Index(name = "idx_app_second_choice_search",
35-
columnList = "verify_status, term, is_delete, second_choice_university_info_for_apply_id"),
35+
columnList = "verify_status, term_id, is_delete, second_choice_university_info_for_apply_id"),
3636
@Index(name = "idx_app_third_choice_search",
37-
columnList = "verify_status, term, is_delete, third_choice_university_info_for_apply_id")
37+
columnList = "verify_status, term_id, is_delete, third_choice_university_info_for_apply_id")
3838
})
3939
public class Application extends BaseEntity {
4040

@@ -59,8 +59,8 @@ public class Application extends BaseEntity {
5959
@Column(columnDefinition = "int not null default 1", name = "update_count")
6060
private Integer updateCount;
6161

62-
@Column(length = 50, nullable = false, name = "term")
63-
private String term;
62+
@Column(nullable = false, name = "term_id")
63+
private long termId;
6464

6565
@Column(name = "is_delete")
6666
private boolean isDelete = false;
@@ -81,11 +81,11 @@ public Application(
8181
SiteUser siteUser,
8282
Gpa gpa,
8383
LanguageTest languageTest,
84-
String term) {
84+
long termId) {
8585
this.siteUserId = siteUser.getId();
8686
this.gpa = gpa;
8787
this.languageTest = languageTest;
88-
this.term = term;
88+
this.termId = termId;
8989
this.updateCount = 1;
9090
this.verifyStatus = PENDING;
9191
}
@@ -94,7 +94,7 @@ public Application(
9494
SiteUser siteUser,
9595
Gpa gpa,
9696
LanguageTest languageTest,
97-
String term,
97+
long termId,
9898
Integer updateCount,
9999
long firstChoiceUnivApplyInfoId,
100100
Long secondChoiceUnivApplyInfoId,
@@ -103,7 +103,7 @@ public Application(
103103
this.siteUserId = siteUser.getId();
104104
this.gpa = gpa;
105105
this.languageTest = languageTest;
106-
this.term = term;
106+
this.termId = termId;
107107
this.updateCount = updateCount;
108108
this.firstChoiceUnivApplyInfoId = firstChoiceUnivApplyInfoId;
109109
this.secondChoiceUnivApplyInfoId = secondChoiceUnivApplyInfoId;
@@ -116,15 +116,15 @@ public Application(
116116
SiteUser siteUser,
117117
Gpa gpa,
118118
LanguageTest languageTest,
119-
String term,
119+
long termId,
120120
long firstChoiceUnivApplyInfoId,
121121
Long secondChoiceUnivApplyInfoId,
122122
Long thirdChoiceUnivApplyInfoId,
123123
String nicknameForApply) {
124124
this.siteUserId = siteUser.getId();
125125
this.gpa = gpa;
126126
this.languageTest = languageTest;
127-
this.term = term;
127+
this.termId = termId;
128128
this.updateCount = 1;
129129
this.firstChoiceUnivApplyInfoId = firstChoiceUnivApplyInfoId;
130130
this.secondChoiceUnivApplyInfoId = secondChoiceUnivApplyInfoId;

src/main/java/com/example/solidconnection/application/repository/ApplicationRepository.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@ public interface ApplicationRepository extends JpaRepository<Application, Long>
2222
OR a.secondChoiceUnivApplyInfoId IN :univApplyInfoIds
2323
OR a.thirdChoiceUnivApplyInfoId IN :univApplyInfoIds)
2424
AND a.verifyStatus = :status
25-
AND a.term = :term
25+
AND a.termId = :termId
2626
AND a.isDelete = false
2727
""")
28-
List<Application> findAllByUnivApplyInfoIds(@Param("univApplyInfoIds") List<Long> univApplyInfoIds, @Param("status") VerifyStatus status, @Param("term") String term);
28+
List<Application> findAllByUnivApplyInfoIds(@Param("univApplyInfoIds") List<Long> univApplyInfoIds, @Param("status") VerifyStatus status, @Param("termId") long termId);
2929

3030
@Query("""
3131
SELECT a
3232
FROM Application a
3333
WHERE a.siteUserId = :siteUserId
34-
AND a.term = :term
34+
AND a.termId = :termId
3535
AND a.isDelete = false
3636
""")
37-
Optional<Application> findBySiteUserIdAndTerm(@Param("siteUserId") long siteUserId, @Param("term") String term);
37+
Optional<Application> findBySiteUserIdAndTermId(@Param("siteUserId") long siteUserId, @Param("termId") long termId);
3838

39-
default Application getApplicationBySiteUserIdAndTerm(long siteUserId, String term) {
40-
return findBySiteUserIdAndTerm(siteUserId, term)
39+
default Application getApplicationBySiteUserIdAndTermId(long siteUserId, long termId) {
40+
return findBySiteUserIdAndTermId(siteUserId, termId)
4141
.orElseThrow(() -> new CustomException(APPLICATION_NOT_FOUND));
4242
}
4343
}

src/main/java/com/example/solidconnection/application/service/ApplicationQueryService.java

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

33
import static com.example.solidconnection.common.exception.ErrorCode.APPLICATION_NOT_APPROVED;
4+
import static com.example.solidconnection.common.exception.ErrorCode.CURRENT_TERM_NOT_FOUND;
45
import static com.example.solidconnection.common.exception.ErrorCode.USER_NOT_FOUND;
56

67
import com.example.solidconnection.application.domain.Application;
@@ -11,6 +12,8 @@
1112
import com.example.solidconnection.common.exception.CustomException;
1213
import com.example.solidconnection.siteuser.domain.SiteUser;
1314
import com.example.solidconnection.siteuser.repository.SiteUserRepository;
15+
import com.example.solidconnection.term.domain.Term;
16+
import com.example.solidconnection.term.repository.TermRepository;
1417
import com.example.solidconnection.university.domain.UnivApplyInfo;
1518
import com.example.solidconnection.university.repository.UnivApplyInfoRepository;
1619
import com.example.solidconnection.university.repository.custom.UnivApplyInfoFilterRepositoryImpl;
@@ -24,7 +27,6 @@
2427
import java.util.stream.Collectors;
2528
import java.util.stream.Stream;
2629
import lombok.RequiredArgsConstructor;
27-
import org.springframework.beans.factory.annotation.Value;
2830
import org.springframework.stereotype.Service;
2931
import org.springframework.transaction.annotation.Transactional;
3032

@@ -36,9 +38,7 @@ public class ApplicationQueryService {
3638
private final UnivApplyInfoRepository univApplyInfoRepository;
3739
private final UnivApplyInfoFilterRepositoryImpl universityFilterRepository;
3840
private final SiteUserRepository siteUserRepository;
39-
40-
@Value("${university.term}")
41-
public String term;
41+
private final TermRepository termRepository;
4242

4343
// todo: 캐싱 정책 변경 시 수정 필요
4444
@Transactional(readOnly = true)
@@ -47,15 +47,20 @@ public ApplicationsResponse getApplicants(long siteUserId, String regionCode, St
4747
SiteUser siteUser = siteUserRepository.findById(siteUserId)
4848
.orElseThrow(() -> new CustomException(USER_NOT_FOUND));
4949
List<String> keywords = StringUtils.isNotBlank(keyword) ? List.of(keyword) : List.of();
50-
List<UnivApplyInfo> univApplyInfos = universityFilterRepository.findAllByRegionCodeAndKeywordsAndTerm(regionCode, keywords, term);
50+
51+
Term term = termRepository.findByIsCurrentTrue()
52+
.orElseThrow(() -> new CustomException(CURRENT_TERM_NOT_FOUND));
53+
54+
List<UnivApplyInfo> univApplyInfos = universityFilterRepository.findAllByRegionCodeAndKeywordsAndTermId(regionCode, keywords, term.getId());
5155
if (univApplyInfos.isEmpty()) {
5256
return new ApplicationsResponse(List.of(), List.of(), List.of());
5357
}
58+
5459
// 2. 조건에 맞는 모든 Application 한 번에 조회
5560
List<Long> univApplyInfoIds = univApplyInfos.stream()
5661
.map(UnivApplyInfo::getId)
5762
.toList();
58-
List<Application> applications = applicationRepository.findAllByUnivApplyInfoIds(univApplyInfoIds, VerifyStatus.APPROVED, term);
63+
List<Application> applications = applicationRepository.findAllByUnivApplyInfoIds(univApplyInfoIds, VerifyStatus.APPROVED, term.getId());
5964
// 3. 지원서 분류 및 DTO 변환
6065
return classifyApplicationsByChoice(univApplyInfos, applications, siteUser);
6166
}
@@ -64,7 +69,11 @@ public ApplicationsResponse getApplicants(long siteUserId, String regionCode, St
6469
public ApplicationsResponse getApplicantsByUserApplications(long siteUserId) {
6570
SiteUser siteUser = siteUserRepository.findById(siteUserId)
6671
.orElseThrow(() -> new CustomException(USER_NOT_FOUND));
67-
Application userLatestApplication = applicationRepository.getApplicationBySiteUserIdAndTerm(siteUser.getId(), term);
72+
73+
Term term = termRepository.findByIsCurrentTrue()
74+
.orElseThrow(() -> new CustomException(CURRENT_TERM_NOT_FOUND));
75+
76+
Application userLatestApplication = applicationRepository.getApplicationBySiteUserIdAndTermId(siteUser.getId(), term.getId());
6877

6978
List<Long> univApplyInfoIds = Stream.of(
7079
userLatestApplication.getFirstChoiceUnivApplyInfoId(),
@@ -78,7 +87,7 @@ public ApplicationsResponse getApplicantsByUserApplications(long siteUserId) {
7887
return new ApplicationsResponse(List.of(), List.of(), List.of());
7988
}
8089

81-
List<Application> applications = applicationRepository.findAllByUnivApplyInfoIds(univApplyInfoIds, VerifyStatus.APPROVED, term);
90+
List<Application> applications = applicationRepository.findAllByUnivApplyInfoIds(univApplyInfoIds, VerifyStatus.APPROVED, term.getId());
8291
List<UnivApplyInfo> univApplyInfos = univApplyInfoRepository.findAllByIds(univApplyInfoIds);
8392

8493
return classifyApplicationsByChoice(univApplyInfos, applications, siteUser);
@@ -130,7 +139,11 @@ private List<ApplicantsResponse> createUniversityApplicantsResponses(
130139
public void validateSiteUserCanViewApplicants(long siteUserId) {
131140
SiteUser siteUser = siteUserRepository.findById(siteUserId)
132141
.orElseThrow(() -> new CustomException(USER_NOT_FOUND));
133-
VerifyStatus verifyStatus = applicationRepository.getApplicationBySiteUserIdAndTerm(siteUser.getId(), term).getVerifyStatus();
142+
143+
Term term = termRepository.findByIsCurrentTrue()
144+
.orElseThrow(() -> new CustomException(CURRENT_TERM_NOT_FOUND));
145+
146+
VerifyStatus verifyStatus = applicationRepository.getApplicationBySiteUserIdAndTermId(siteUser.getId(), term.getId()).getVerifyStatus();
134147
if (verifyStatus != VerifyStatus.APPROVED) {
135148
throw new CustomException(APPLICATION_NOT_APPROVED);
136149
}

src/main/java/com/example/solidconnection/application/service/ApplicationSubmissionService.java

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

33
import static com.example.solidconnection.common.exception.ErrorCode.APPLY_UPDATE_LIMIT_EXCEED;
4+
import static com.example.solidconnection.common.exception.ErrorCode.CURRENT_TERM_NOT_FOUND;
45
import static com.example.solidconnection.common.exception.ErrorCode.GPA_SCORE_NOT_FOUND;
56
import static com.example.solidconnection.common.exception.ErrorCode.INVALID_GPA_SCORE_STATUS;
67
import static com.example.solidconnection.common.exception.ErrorCode.INVALID_LANGUAGE_TEST_SCORE;
@@ -20,9 +21,10 @@
2021
import com.example.solidconnection.score.repository.LanguageTestScoreRepository;
2122
import com.example.solidconnection.siteuser.domain.SiteUser;
2223
import com.example.solidconnection.siteuser.repository.SiteUserRepository;
24+
import com.example.solidconnection.term.domain.Term;
25+
import com.example.solidconnection.term.repository.TermRepository;
2326
import java.util.Optional;
2427
import lombok.RequiredArgsConstructor;
25-
import org.springframework.beans.factory.annotation.Value;
2628
import org.springframework.stereotype.Service;
2729
import org.springframework.transaction.annotation.Transactional;
2830

@@ -36,9 +38,7 @@ public class ApplicationSubmissionService {
3638
private final GpaScoreRepository gpaScoreRepository;
3739
private final LanguageTestScoreRepository languageTestScoreRepository;
3840
private final SiteUserRepository siteUserRepository;
39-
40-
@Value("${university.term}")
41-
private String term;
41+
private final TermRepository termRepository;
4242

4343
// 학점 및 어학성적이 모두 유효한 경우에만 지원서 등록이 가능하다.
4444
// 기존에 있던 status field 우선 APRROVED로 입력시킨다.
@@ -49,12 +49,14 @@ public ApplicationSubmissionResponse apply(long siteUserId, ApplyRequest applyRe
4949
UnivApplyInfoChoiceRequest univApplyInfoChoiceRequest = applyRequest.univApplyInfoChoiceRequest();
5050
GpaScore gpaScore = getValidGpaScore(siteUser, applyRequest.gpaScoreId());
5151
LanguageTestScore languageTestScore = getValidLanguageTestScore(siteUser, applyRequest.languageTestScoreId());
52+
Term term = termRepository.findByIsCurrentTrue()
53+
.orElseThrow(() -> new CustomException(CURRENT_TERM_NOT_FOUND));
5254

5355
long firstChoiceUnivApplyInfoId = univApplyInfoChoiceRequest.firstChoiceUnivApplyInfoId();
5456
Long secondChoiceUnivApplyInfoId = univApplyInfoChoiceRequest.secondChoiceUnivApplyInfoId();
5557
Long thirdChoiceUnivApplyInfoId = univApplyInfoChoiceRequest.thirdChoiceUnivApplyInfoId();
5658

57-
Optional<Application> existingApplication = applicationRepository.findBySiteUserIdAndTerm(siteUser.getId(), term);
59+
Optional<Application> existingApplication = applicationRepository.findBySiteUserIdAndTermId(siteUser.getId(), term.getId());
5860
int updateCount = existingApplication
5961
.map(application -> {
6062
validateUpdateLimitNotExceed(application);
@@ -67,7 +69,7 @@ public ApplicationSubmissionResponse apply(long siteUserId, ApplyRequest applyRe
6769
siteUser,
6870
gpaScore.getGpa(),
6971
languageTestScore.getLanguageTest(),
70-
term,
72+
term.getId(),
7173
updateCount,
7274
firstChoiceUnivApplyInfoId,
7375
secondChoiceUnivApplyInfoId,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public enum ErrorCode {
4848
CHAT_PARTNER_NOT_FOUND(HttpStatus.BAD_REQUEST.value(), "채팅 상대를 찾을 수 없습니다."),
4949
CHAT_PARTICIPANT_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "채팅 참여자를 찾을 수 없습니다."),
5050
BLOCK_USER_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "차단 대상 사용자를 찾을 수 없습니다."),
51+
TERM_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "존재하지 않는 학기입니다."),
52+
CURRENT_TERM_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "현재 학기를 찾을 수 없습니다."),
5153

5254
// auth
5355
USER_ALREADY_SIGN_OUT(HttpStatus.UNAUTHORIZED.value(), "로그아웃 되었습니다."),

src/main/java/com/example/solidconnection/mentor/domain/Mentor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public class Mentor extends BaseEntity {
4545
@Column
4646
private long universityId;
4747

48-
@Column(length = 50, nullable = false)
49-
private String term;
48+
@Column(nullable = false, name = "term_id")
49+
private long termId;
5050

5151
@BatchSize(size = 10)
5252
@OrderBy("sequence ASC")

src/main/java/com/example/solidconnection/mentor/dto/MatchedMentorResponse.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,17 @@ public record MatchedMentorResponse(
2727
) {
2828

2929
public static MatchedMentorResponse of(Mentor mentor, SiteUser mentorUser,
30-
University university, boolean isApplied, Long roomId) {
30+
University university, boolean isApplied, Long roomId,
31+
String termName
32+
) {
3133
return new MatchedMentorResponse(
3234
mentor.getId(),
3335
roomId,
3436
mentorUser.getNickname(),
3537
mentorUser.getProfileImageUrl(),
3638
university.getCountry().getKoreanName(),
3739
university.getKoreanName(),
38-
mentor.getTerm(),
40+
termName,
3941
mentor.getMenteeCount(),
4042
mentor.isHasBadge(),
4143
mentor.getIntroduction(),

src/main/java/com/example/solidconnection/mentor/dto/MentorDetailResponse.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ public record MentorDetailResponse(
2121
) {
2222

2323
public static MentorDetailResponse of(Mentor mentor, SiteUser mentorUser,
24-
University university, boolean isApplied) {
24+
University university, boolean isApplied,
25+
String termName
26+
) {
2527
return new MentorDetailResponse(
2628
mentor.getId(),
2729
mentorUser.getNickname(),
2830
mentorUser.getProfileImageUrl(),
2931
university.getCountry().getKoreanName(),
3032
university.getKoreanName(),
31-
mentor.getTerm(),
33+
termName,
3234
mentor.getMenteeCount(),
3335
mentor.isHasBadge(),
3436
mentor.getIntroduction(),

src/main/java/com/example/solidconnection/mentor/dto/MentorMyPageResponse.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ public record MentorMyPageResponse(
1919
List<ChannelResponse> channels
2020
) {
2121

22-
public static MentorMyPageResponse of(Mentor mentor, SiteUser siteUser, University university) {
22+
public static MentorMyPageResponse of(Mentor mentor, SiteUser siteUser, University university, String termName) {
2323
return new MentorMyPageResponse(
2424
mentor.getId(),
2525
siteUser.getProfileImageUrl(),
2626
siteUser.getNickname(),
2727
university.getCountry().getKoreanName(),
2828
university.getKoreanName(),
29-
mentor.getTerm(),
29+
termName,
3030
mentor.getMenteeCount(),
3131
mentor.isHasBadge(),
3232
mentor.getIntroduction(),

src/main/java/com/example/solidconnection/mentor/dto/MentorPreviewResponse.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@ public record MentorPreviewResponse(
2020
) {
2121

2222
public static MentorPreviewResponse of(Mentor mentor, SiteUser mentorUser,
23-
University university, boolean isApplied) {
23+
University university, boolean isApplied,
24+
String termName
25+
) {
2426
return new MentorPreviewResponse(
2527
mentor.getId(),
2628
mentorUser.getNickname(),
2729
mentorUser.getProfileImageUrl(),
2830
university.getCountry().getKoreanName(),
2931
university.getKoreanName(),
30-
mentor.getTerm(),
32+
termName,
3133
mentor.getMenteeCount(),
3234
mentor.isHasBadge(),
3335
mentor.getIntroduction(),

0 commit comments

Comments
 (0)