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 @@ -67,7 +67,6 @@ public AdminHostUniversityDetailResponse getHostUniversity(Long id) {
)
public AdminHostUniversityDetailResponse createHostUniversity(AdminHostUniversityCreateRequest request) {
validateKoreanNameNotExists(request.koreanName());
validateEnglishNameNotExists(request.englishName());

Country country = findCountryByCode(request.countryCode());
Region region = findRegionByCode(request.regionCode());
Expand Down Expand Up @@ -98,13 +97,6 @@ private void validateKoreanNameNotExists(String koreanName) {
});
}

private void validateEnglishNameNotExists(String englishName) {
hostUniversityRepository.findByEnglishName(englishName)
.ifPresent(existingUniversity -> {
throw new CustomException(HOST_UNIVERSITY_ALREADY_EXISTS);
});
}

@Transactional
@DefaultCacheOut(
key = {"univApplyInfoTextSearch", "university:recommend:general"},
Expand All @@ -116,7 +108,6 @@ public AdminHostUniversityDetailResponse updateHostUniversity(Long id, AdminHost
.orElseThrow(() -> new CustomException(UNIVERSITY_NOT_FOUND));

validateKoreanNameNotDuplicated(request.koreanName(), id);
validateEnglishNameNotDuplicated(request.englishName(), id);

Country country = findCountryByCode(request.countryCode());
Region region = findRegionByCode(request.regionCode());
Expand Down Expand Up @@ -149,15 +140,6 @@ private void validateKoreanNameNotDuplicated(String koreanName, Long excludeId)
});
}

private void validateEnglishNameNotDuplicated(String englishName, Long excludeId) {
hostUniversityRepository.findByEnglishName(englishName)
.ifPresent(existingUniversity -> {
if (!existingUniversity.getId().equals(excludeId)) {
throw new CustomException(HOST_UNIVERSITY_ALREADY_EXISTS);
}
});
}

private Country findCountryByCode(String countryCode) {
return countryRepository.findByCode(countryCode)
.orElseThrow(() -> new CustomException(COUNTRY_NOT_FOUND));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class HostUniversity extends BaseEntity {
@Column(name = "korean_name", nullable = false, unique = true, length = 100)
private String koreanName;

@Column(name = "english_name", nullable = false, unique = true, length = 200)
@Column(name = "english_name", nullable = false, length = 200)
private String englishName;

@Column(name = "format_name", nullable = false, length = 100)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,4 @@ default HostUniversity getHostUniversityById(Long id) {
}

Optional<HostUniversity> findByKoreanName(String koreanName);

Optional<HostUniversity> findByEnglishName(String englishName);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ class 생성 {
}

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

// when & then
assertThatCode(() -> adminHostUniversityService.createHostUniversity(request))
.isInstanceOf(CustomException.class)
.hasMessage(ErrorCode.HOST_UNIVERSITY_ALREADY_EXISTS.getMessage());
// when
AdminHostUniversityDetailResponse response = adminHostUniversityService.createHostUniversity(request);

// then
assertThat(response.koreanName()).isEqualTo(request.koreanName());
assertThat(response.englishName()).isEqualTo(existing.getEnglishName());
}
}

Expand Down Expand Up @@ -367,7 +369,7 @@ class 수정 {
}

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

// when & then
assertThatCode(() -> adminHostUniversityService.updateHostUniversity(university1.getId(), request))
.isInstanceOf(CustomException.class)
.hasMessage(ErrorCode.HOST_UNIVERSITY_ALREADY_EXISTS.getMessage());
// when
AdminHostUniversityDetailResponse response = adminHostUniversityService.updateHostUniversity(
university1.getId(), request);

// then
assertThat(response.koreanName()).isEqualTo(university1.getKoreanName());
assertThat(response.englishName()).isEqualTo(university2.getEnglishName());
}

@Test
Expand Down
Loading