Skip to content

Commit f97f573

Browse files
committed
refactor: 기관 프로필 조회 리팩토링
- 기존 userId를 이용한 조회에서 기관 자체 PK를 이용한 조회 방식으로 리팩토링 - 테스트및 검증 완료
1 parent 2fe5c25 commit f97f573

File tree

8 files changed

+27
-26
lines changed

8 files changed

+27
-26
lines changed

src/main/java/com/somemore/center/controller/CenterQueryApiController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ public class CenterQueryApiController {
2222
private final NEWCenterQueryUseCase centerQueryUseCase;
2323

2424
@Operation(summary = "기관 프로필 조회 API")
25-
@GetMapping("/profile/{userId}")
26-
public ApiResponse<CenterProfileResponseDto> getCenterProfile(@PathVariable UUID userId) {
25+
@GetMapping("/profile/{centerId}")
26+
public ApiResponse<CenterProfileResponseDto> getCenterProfile(@PathVariable UUID centerId) {
2727

28-
CenterProfileResponseDto responseDto = centerQueryUseCase.getCenterProfileByUserId(userId);
28+
CenterProfileResponseDto responseDto = centerQueryUseCase.getCenterProfileById(centerId);
2929

3030
return ApiResponse.ok(200, responseDto, "기관 프로필 조회 성공");
3131
}

src/main/java/com/somemore/center/repository/NEWCenterRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ public interface NEWCenterRepository {
1414

1515
Optional<NEWCenter> findByUserId(UUID userId);
1616

17-
Optional<CenterProfileDto> findCenterProfileByUserId(UUID userId);
17+
Optional<CenterProfileDto> findCenterProfileById(UUID centerId);
1818
}

src/main/java/com/somemore/center/repository/NEWCenterRepositoryImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,16 @@ public Optional<NEWCenter> findByUserId(UUID userId) {
5151
);
5252
}
5353

54-
public Optional<CenterProfileDto> findCenterProfileByUserId(UUID userId) {
54+
@Override
55+
public Optional<CenterProfileDto> findCenterProfileById(UUID centerId) {
5556
return Optional.ofNullable(
5657
queryFactory.select(Projections.constructor(CenterProfileDto.class,
5758
center.id,
5859
center.userId,
5960
center.homepageUrl))
6061
.from(center)
6162
.where(
62-
center.userId.eq(userId),
63+
center.id.eq(centerId),
6364
isNotDeleted()
6465
)
6566
.fetchOne()

src/main/java/com/somemore/center/service/NEWCenterQueryService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ public UUID getIdByUserId(UUID userId) {
3939
}
4040

4141
@Override
42-
public CenterProfileResponseDto getCenterProfileByUserId(UUID userId) {
42+
public CenterProfileResponseDto getCenterProfileById(UUID centerId) {
4343

44-
CenterProfileDto centerProfileDto = centerRepository.findCenterProfileByUserId(userId)
44+
CenterProfileDto centerProfileDto = centerRepository.findCenterProfileById(centerId)
4545
.orElseThrow(() -> new NoSuchElementException(ExceptionMessage.NOT_EXISTS_CENTER));
4646

47-
UserProfileDto userProfileDto = userQueryUseCase.getUserProfileByUserId(userId);
47+
UserProfileDto userProfileDto = userQueryUseCase.getUserProfileByUserId(centerProfileDto.userId());
4848

4949
List<PreferItemResponseDto> preferItems = preferItemQueryUseCase.getPreferItemDtosByCenterId(centerProfileDto.id());
5050

src/main/java/com/somemore/center/usecase/NEWCenterQueryUseCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ public interface NEWCenterQueryUseCase {
1111

1212
UUID getIdByUserId(UUID userId);
1313

14-
CenterProfileResponseDto getCenterProfileByUserId(UUID userId);
14+
CenterProfileResponseDto getCenterProfileById(UUID centerId);
1515
}

src/test/java/com/somemore/center/controller/CenterQueryApiControllerTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ class CenterQueryApiControllerTest extends ControllerTestSupport {
2525
@MockBean
2626
protected NEWCenterQueryUseCase centerQueryUseCase;
2727

28-
private UUID userId;
28+
private UUID centerId;
2929
private CenterProfileResponseDto responseDto;
3030

3131
@BeforeEach
3232
void setUp() {
33-
userId = UUID.randomUUID();
33+
centerId = UUID.randomUUID();
3434
responseDto = CenterProfileResponseDto.builder()
35-
.id(userId)
35+
.id(centerId)
3636
.userId(UUID.randomUUID())
3737
.homepageUrl("http://example.com")
3838
.name("Test Center")
@@ -43,21 +43,21 @@ void setUp() {
4343
.build();
4444
}
4545

46-
@DisplayName("유저 ID로 기관 유저 프로필을 조회할 수 있다. (controller)")
46+
@DisplayName("기관 ID로 기관 프로필을 조회할 수 있다. (controller)")
4747
@Test
4848
void getCenterProfile() throws Exception {
4949
// given
50-
when(centerQueryUseCase.getCenterProfileByUserId(userId)).thenReturn(responseDto);
50+
when(centerQueryUseCase.getCenterProfileById(centerId)).thenReturn(responseDto);
5151

5252
// when & then
5353
mockMvc.perform(
54-
get("/api/center/profile/{userId}", userId)
54+
get("/api/center/profile/{centerId}", centerId)
5555
.contentType(MediaType.APPLICATION_JSON)
5656
)
5757
.andExpect(status().isOk())
5858
.andExpect(jsonPath("$.code").value("200"))
5959
.andExpect(jsonPath("$.message").value("기관 프로필 조회 성공"))
60-
.andExpect(jsonPath("$.data.id").value(userId.toString()))
60+
.andExpect(jsonPath("$.data.id").value(centerId.toString()))
6161
.andExpect(jsonPath("$.data.user_id").value(responseDto.userId().toString()))
6262
.andExpect(jsonPath("$.data.homepage_url").value(responseDto.homepageUrl()))
6363
.andExpect(jsonPath("$.data.name").value(responseDto.name()))
@@ -66,27 +66,27 @@ void getCenterProfile() throws Exception {
6666
.andExpect(jsonPath("$.data.introduce").value(responseDto.introduce()))
6767
.andExpect(jsonPath("$.data.prefer_items").isArray());
6868

69-
verify(centerQueryUseCase, times(1)).getCenterProfileByUserId(userId);
69+
verify(centerQueryUseCase, times(1)).getCenterProfileById(centerId);
7070
}
7171

7272
@DisplayName("존재하지 않는 유저 ID로 조회 시 예외가 발생한다. (controller)")
7373
@Test
7474
void getCenterProfile_NotFound() throws Exception {
7575
// given
7676
UUID nonExistentuserId = UUID.randomUUID();
77-
when(centerQueryUseCase.getCenterProfileByUserId(nonExistentuserId))
77+
when(centerQueryUseCase.getCenterProfileById(nonExistentuserId))
7878
.thenThrow(new BadRequestException(NOT_EXISTS_CENTER.getMessage()));
7979

8080
// when & then
8181
mockMvc.perform(
82-
get("/api/center/profile/{userId}", nonExistentuserId)
82+
get("/api/center/profile/{centerId}", nonExistentuserId)
8383
.contentType(MediaType.APPLICATION_JSON)
8484
)
8585
.andExpect(status().isBadRequest())
8686
.andExpect(jsonPath("$.status").value("400"))
8787
.andExpect(jsonPath("$.detail").value("존재하지 않는 기관입니다."));
8888

89-
verify(centerQueryUseCase, times(1)).getCenterProfileByUserId(nonExistentuserId);
89+
verify(centerQueryUseCase, times(1)).getCenterProfileById(nonExistentuserId);
9090
}
9191

9292
}

src/test/java/com/somemore/center/repository/NEWCenterRepositoryImplTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void saveVolunteerByUserId() {
3939

4040
}
4141

42-
@DisplayName("유저 아이디로 기관 정보를 가져올 수 있다.")
42+
@DisplayName("기관 아이디로 기관 프로필 정보를 가져올 수 있다.")
4343
@Test
4444
void findCenterProfileByUserId() {
4545

@@ -49,7 +49,7 @@ void findCenterProfileByUserId() {
4949
centerRepository.save(center);
5050

5151
// when
52-
Optional<CenterProfileDto> result = centerRepository.findCenterProfileByUserId(userId);
52+
Optional<CenterProfileDto> result = centerRepository.findCenterProfileById(center.getId());
5353

5454
// then
5555
assertThat(result).isPresent();
@@ -63,10 +63,10 @@ void findCenterProfileByUserId() {
6363
void findCenterProfileByUserId_NoResult() {
6464

6565
// given
66-
UUID nonExistentUserId = UUID.randomUUID();
66+
UUID nonExistentCenterId = UUID.randomUUID();
6767

6868
// when
69-
Optional<CenterProfileDto> result = centerRepository.findCenterProfileByUserId(nonExistentUserId);
69+
Optional<CenterProfileDto> result = centerRepository.findCenterProfileById(nonExistentCenterId);
7070

7171
// then
7272
assertThat(result).isEmpty();

src/test/java/com/somemore/center/service/NEWCenterQueryServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void getCenterProfileByUserId() {
9090
List<PreferItemResponseDto> preferItems = preferItemQueryUseCase.getPreferItemDtosByCenterId(center.getId());
9191

9292
//when
93-
CenterProfileResponseDto result = centerQueryService.getCenterProfileByUserId(userId);
93+
CenterProfileResponseDto result = centerQueryService.getCenterProfileById(center.getId());
9494

9595
//then
9696
assertThat(result).isNotNull();

0 commit comments

Comments
 (0)