-
Notifications
You must be signed in to change notification settings - Fork 8
feat: region 관련 관리 기능 추가 #561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Gyuhyeok99
merged 5 commits into
solid-connection:develop
from
Gyuhyeok99:feat/559-admin-region
Dec 21, 2025
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6e8dc15
feat: 지역 생성 기능 구현 (AdminRegion)
Gyuhyeok99 92305a0
feat: 지역 수정/삭제/조회 기능 구현 및 테스트 추가 (AdminRegion)
Gyuhyeok99 329a7cc
fix: 지역 관리 관련 에러코드 추가 (ErrorCode)
Gyuhyeok99 fa6dda5
fix: jpa 오류 수정
Gyuhyeok99 eefc764
refactor: 코드리뷰 반영
Gyuhyeok99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
.../java/com/example/solidconnection/admin/location/region/dto/AdminRegionUpdateRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.example.solidconnection.admin.location.region.dto; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.Size; | ||
|
|
||
| public record AdminRegionUpdateRequest( | ||
| @NotBlank(message = "한글 지역명은 필수입니다") | ||
| @Size(min = 1, max = 100, message = "한글 지역명은 1자 이상 100자 이하여야 합니다") | ||
| String koreanName | ||
| ) { | ||
|
|
||
| } |
197 changes: 197 additions & 0 deletions
197
...ava/com/example/solidconnection/admin/location/region/service/AdminRegionServiceTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,197 @@ | ||
| package com.example.solidconnection.admin.location.region.service; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatCode; | ||
|
|
||
| import com.example.solidconnection.admin.location.region.dto.AdminRegionCreateRequest; | ||
| import com.example.solidconnection.admin.location.region.dto.AdminRegionResponse; | ||
| import com.example.solidconnection.admin.location.region.dto.AdminRegionUpdateRequest; | ||
| import com.example.solidconnection.common.exception.CustomException; | ||
| import com.example.solidconnection.common.exception.ErrorCode; | ||
| import com.example.solidconnection.location.region.domain.Region; | ||
| import com.example.solidconnection.location.region.fixture.RegionFixture; | ||
| import com.example.solidconnection.location.region.repository.RegionRepository; | ||
| import com.example.solidconnection.support.TestContainerSpringBootTest; | ||
| import java.util.List; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Nested; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
|
|
||
| @TestContainerSpringBootTest | ||
| @DisplayName("지역 관련 관리자 서비스 테스트") | ||
| class AdminRegionServiceTest { | ||
|
|
||
| @Autowired | ||
| private AdminRegionService adminRegionService; | ||
|
|
||
| @Autowired | ||
| private RegionRepository regionRepository; | ||
|
|
||
| @Autowired | ||
| private RegionFixture regionFixture; | ||
|
|
||
| @Nested | ||
| class 전체_지역_조회 { | ||
|
|
||
| @Test | ||
| void 지역이_없으면_빈_목록을_반환한다() { | ||
| // when | ||
| List<AdminRegionResponse> responses = adminRegionService.getAllRegions(); | ||
|
|
||
| // then | ||
| assertThat(responses).isEqualTo(List.of()); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("저장된 모든 지역을 조회한다") | ||
|
||
| void 저장된_모든_지역을_조회한다() { | ||
| // given | ||
| Region region1 = regionFixture.영미권(); | ||
| Region region2 = regionFixture.유럽(); | ||
| Region region3 = regionFixture.아시아(); | ||
|
|
||
| // when | ||
| List<AdminRegionResponse> responses = adminRegionService.getAllRegions(); | ||
|
|
||
| // then | ||
| assertThat(responses) | ||
| .hasSize(3) | ||
| .extracting(AdminRegionResponse::code) | ||
| .containsExactlyInAnyOrder( | ||
| region1.getCode(), | ||
| region2.getCode(), | ||
| region3.getCode() | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| @Nested | ||
| class 지역_생성 { | ||
|
|
||
| @Test | ||
| void 유효한_정보로_지역을_생성하면_성공한다() { | ||
| // given | ||
| AdminRegionCreateRequest request = new AdminRegionCreateRequest("KR_SEOUL", "서울"); | ||
|
|
||
| // when | ||
| AdminRegionResponse response = adminRegionService.createRegion(request); | ||
|
|
||
| // then | ||
| assertThat(response.code()).isEqualTo("KR_SEOUL"); | ||
|
|
||
| // 데이터베이스에 저장되었는지 확인 | ||
| Region savedRegion = regionRepository.findById(request.code()).orElseThrow(); | ||
| assertThat(savedRegion.getKoreanName()).isEqualTo(request.koreanName()); | ||
| } | ||
|
|
||
| @Test | ||
| void 이미_존재하는_코드로_지역을_생성하면_예외_응답을_반환한다() { | ||
| // given | ||
| regionFixture.영미권(); | ||
|
|
||
| AdminRegionCreateRequest request = new AdminRegionCreateRequest("AMERICAS", "새로운 영미권"); | ||
|
|
||
| // when & then | ||
| assertThatCode(() -> adminRegionService.createRegion(request)) | ||
| .isInstanceOf(CustomException.class) | ||
| .hasMessage(ErrorCode.REGION_ALREADY_EXISTS.getMessage()); | ||
| } | ||
|
|
||
| @Test | ||
| void 이미_존재하는_한글명으로_지역을_생성하면_예외_응답을_반환한다() { | ||
| // given | ||
| regionFixture.유럽(); | ||
|
|
||
| AdminRegionCreateRequest request = new AdminRegionCreateRequest("NEW_CODE", "유럽"); | ||
|
|
||
| // when & then | ||
| assertThatCode(() -> adminRegionService.createRegion(request)) | ||
| .isInstanceOf(CustomException.class) | ||
| .hasMessage(ErrorCode.REGION_ALREADY_EXISTS.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| @Nested | ||
| class 지역_수정 { | ||
|
|
||
| @Test | ||
| void 유효한_정보로_지역을_수정하면_성공한다() { | ||
| // given | ||
| Region region = regionFixture.영미권(); | ||
|
|
||
| AdminRegionUpdateRequest request = new AdminRegionUpdateRequest("미주"); | ||
|
|
||
| // when | ||
| AdminRegionResponse response = adminRegionService.updateRegion(region.getCode(), request); | ||
|
|
||
| // then | ||
| assertThat(response.code()).isEqualTo(region.getCode()); | ||
| Region updatedRegion = regionRepository.findById(region.getCode()).orElseThrow(); | ||
| assertThat(updatedRegion.getKoreanName()).isEqualTo(request.koreanName()); | ||
| } | ||
|
|
||
| @Test | ||
| void 존재하지_않는_지역_코드로_수정하면_예외_응답을_반환한다() { | ||
| // given | ||
| AdminRegionUpdateRequest request = new AdminRegionUpdateRequest("부산"); | ||
|
|
||
| // when & then | ||
| assertThatCode(() -> adminRegionService.updateRegion("NOT_EXIST", request)) | ||
| .isInstanceOf(CustomException.class) | ||
| .hasMessage(ErrorCode.REGION_NOT_FOUND.getMessage()); | ||
| } | ||
|
|
||
| @Test | ||
| void 다른_지역의_한글명으로_수정하면_예외_응답을_반환한다() { | ||
| // given | ||
| Region region1 = regionFixture.영미권(); | ||
| Region region2 = regionFixture.유럽(); | ||
|
|
||
| AdminRegionUpdateRequest request = new AdminRegionUpdateRequest(region2.getKoreanName()); | ||
|
|
||
| // when & then | ||
| assertThatCode(() -> adminRegionService.updateRegion(region1.getCode(), request)) | ||
| .isInstanceOf(CustomException.class) | ||
| .hasMessage(ErrorCode.REGION_ALREADY_EXISTS.getMessage()); | ||
| } | ||
|
|
||
| @Test | ||
| void 같은_지역의_한글명으로_수정하면_성공한다() { | ||
| // given | ||
| Region region = regionFixture.아시아(); | ||
|
|
||
| AdminRegionUpdateRequest request = new AdminRegionUpdateRequest(region.getKoreanName()); | ||
|
|
||
| // when | ||
| AdminRegionResponse response = adminRegionService.updateRegion(region.getCode(), request); | ||
|
|
||
| // then | ||
| assertThat(response.code()).isEqualTo(region.getCode()); | ||
| } | ||
| } | ||
|
|
||
| @Nested | ||
| class 지역_삭제 { | ||
|
|
||
| @Test | ||
| void 존재하는_지역을_삭제하면_성공한다() { | ||
| // given | ||
| Region region = regionFixture.영미권(); | ||
|
|
||
| // when | ||
| adminRegionService.deleteRegion(region.getCode()); | ||
|
|
||
| // then | ||
| assertThat(regionRepository.findById(region.getCode())).isEmpty(); | ||
| } | ||
|
|
||
| @Test | ||
| void 존재하지_않는_지역을_삭제하면_예외_응답을_반환한다() { | ||
| // when & then | ||
| assertThatCode(() -> adminRegionService.deleteRegion("NOT_EXIST")) | ||
| .isInstanceOf(CustomException.class) | ||
| .hasMessage(ErrorCode.REGION_NOT_FOUND.getMessage()); | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저희 서비스에서 테스트 코드에 '// given' 부분 내용이 존재하지 않다면 주석을 아예 빼버려도 되나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
다른 테스트 코드들 보니 안쓰고 있네요!