Skip to content

Commit 443665f

Browse files
authored
fix: english_name UK 제거 (#771)
* refactor: (english_name, korean_name) 조합으로 UK 설정하도록 * refactor: 복합 UK 제거, english_name 중복 허용
1 parent f0acacb commit 443665f

6 files changed

Lines changed: 16 additions & 33 deletions

File tree

src/main/java/com/example/solidconnection/admin/university/service/AdminHostUniversityService.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ public AdminHostUniversityDetailResponse getHostUniversity(Long id) {
6767
)
6868
public AdminHostUniversityDetailResponse createHostUniversity(AdminHostUniversityCreateRequest request) {
6969
validateKoreanNameNotExists(request.koreanName());
70-
validateEnglishNameNotExists(request.englishName());
7170

7271
Country country = findCountryByCode(request.countryCode());
7372
Region region = findRegionByCode(request.regionCode());
@@ -98,13 +97,6 @@ private void validateKoreanNameNotExists(String koreanName) {
9897
});
9998
}
10099

101-
private void validateEnglishNameNotExists(String englishName) {
102-
hostUniversityRepository.findByEnglishName(englishName)
103-
.ifPresent(existingUniversity -> {
104-
throw new CustomException(HOST_UNIVERSITY_ALREADY_EXISTS);
105-
});
106-
}
107-
108100
@Transactional
109101
@DefaultCacheOut(
110102
key = {"univApplyInfoTextSearch", "university:recommend:general"},
@@ -116,7 +108,6 @@ public AdminHostUniversityDetailResponse updateHostUniversity(Long id, AdminHost
116108
.orElseThrow(() -> new CustomException(UNIVERSITY_NOT_FOUND));
117109

118110
validateKoreanNameNotDuplicated(request.koreanName(), id);
119-
validateEnglishNameNotDuplicated(request.englishName(), id);
120111

121112
Country country = findCountryByCode(request.countryCode());
122113
Region region = findRegionByCode(request.regionCode());
@@ -149,15 +140,6 @@ private void validateKoreanNameNotDuplicated(String koreanName, Long excludeId)
149140
});
150141
}
151142

152-
private void validateEnglishNameNotDuplicated(String englishName, Long excludeId) {
153-
hostUniversityRepository.findByEnglishName(englishName)
154-
.ifPresent(existingUniversity -> {
155-
if (!existingUniversity.getId().equals(excludeId)) {
156-
throw new CustomException(HOST_UNIVERSITY_ALREADY_EXISTS);
157-
}
158-
});
159-
}
160-
161143
private Country findCountryByCode(String countryCode) {
162144
return countryRepository.findByCode(countryCode)
163145
.orElseThrow(() -> new CustomException(COUNTRY_NOT_FOUND));

src/main/java/com/example/solidconnection/university/domain/HostUniversity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class HostUniversity extends BaseEntity {
2828
@Column(name = "korean_name", nullable = false, unique = true, length = 100)
2929
private String koreanName;
3030

31-
@Column(name = "english_name", nullable = false, unique = true, length = 200)
31+
@Column(name = "english_name", nullable = false, length = 200)
3232
private String englishName;
3333

3434
@Column(name = "format_name", nullable = false, length = 100)

src/main/java/com/example/solidconnection/university/repository/HostUniversityRepository.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,4 @@ default HostUniversity getHostUniversityById(Long id) {
1616
}
1717

1818
Optional<HostUniversity> findByKoreanName(String koreanName);
19-
20-
Optional<HostUniversity> findByEnglishName(String englishName);
2119
}

src/main/resources/db/migration/V52__add_unique_constraint_to_host_university_english_name.sql

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/main/resources/db/migration/V53__extend_univ_apply_info_import_columns.sql renamed to src/main/resources/db/migration/V52__extend_univ_apply_info_import_columns.sql

File renamed without changes.

src/test/java/com/example/solidconnection/admin/service/AdminHostUniversityServiceTest.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ class 생성 {
258258
}
259259

260260
@Test
261-
void 이미_존재하는_영문명으로_생성하면_예외_응답을_반환한다() {
261+
void 이미_존재하는_영문명이어도_한글명이_다르면_생성한다() {
262262
// given
263263
HostUniversity existing = universityFixture.괌_대학();
264264
Country country = countryFixture.미국();
@@ -276,10 +276,12 @@ class 생성 {
276276
region.getCode()
277277
);
278278

279-
// when & then
280-
assertThatCode(() -> adminHostUniversityService.createHostUniversity(request))
281-
.isInstanceOf(CustomException.class)
282-
.hasMessage(ErrorCode.HOST_UNIVERSITY_ALREADY_EXISTS.getMessage());
279+
// when
280+
AdminHostUniversityDetailResponse response = adminHostUniversityService.createHostUniversity(request);
281+
282+
// then
283+
assertThat(response.koreanName()).isEqualTo(request.koreanName());
284+
assertThat(response.englishName()).isEqualTo(existing.getEnglishName());
283285
}
284286
}
285287

@@ -367,7 +369,7 @@ class 수정 {
367369
}
368370

369371
@Test
370-
void 다른_대학의_영문명으로_수정하면_예외_응답을_반환한다() {
372+
void 다른_대학의_영문명이어도_한글명이_다르면_수정한다() {
371373
// given
372374
HostUniversity university1 = universityFixture.괌_대학();
373375
HostUniversity university2 = universityFixture.메이지_대학();
@@ -384,10 +386,13 @@ class 수정 {
384386
university1.getRegion().getCode()
385387
);
386388

387-
// when & then
388-
assertThatCode(() -> adminHostUniversityService.updateHostUniversity(university1.getId(), request))
389-
.isInstanceOf(CustomException.class)
390-
.hasMessage(ErrorCode.HOST_UNIVERSITY_ALREADY_EXISTS.getMessage());
389+
// when
390+
AdminHostUniversityDetailResponse response = adminHostUniversityService.updateHostUniversity(
391+
university1.getId(), request);
392+
393+
// then
394+
assertThat(response.koreanName()).isEqualTo(university1.getKoreanName());
395+
assertThat(response.englishName()).isEqualTo(university2.getEnglishName());
391396
}
392397

393398
@Test

0 commit comments

Comments
 (0)