Skip to content

Commit 89660a6

Browse files
committed
refactor: 기관 프로필 조회 컨트롤러 리팩토링
- 새로운 center 도메인으로 클래스 이전및 centerId -> userId로 수정 - 테스트및 검증 완료
1 parent d060988 commit 89660a6

File tree

2 files changed

+36
-38
lines changed

2 files changed

+36
-38
lines changed
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
package com.somemore.domains.center.controller;
1+
package com.somemore.center.controller;
22

3-
import com.somemore.domains.center.dto.response.CenterProfileResponseDto;
4-
import com.somemore.domains.center.usecase.query.CenterQueryUseCase;
3+
import com.somemore.center.dto.response.CenterProfileResponseDto;
4+
import com.somemore.center.usecase.NEWCenterQueryUseCase;
55
import com.somemore.global.common.response.ApiResponse;
66
import io.swagger.v3.oas.annotations.Operation;
77
import io.swagger.v3.oas.annotations.tags.Tag;
@@ -19,13 +19,13 @@
1919
@Tag(name = "Center Query API", description = "기관 관련 조회 API를 제공합니다.")
2020
public class CenterQueryApiController {
2121

22-
private final CenterQueryUseCase centerQueryUseCase;
22+
private final NEWCenterQueryUseCase centerQueryUseCase;
2323

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

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

3030
return ApiResponse.ok(200, responseDto, "기관 프로필 조회 성공");
3131
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.somemore.domains.center.controller;
1+
package com.somemore.center.controller;
22

33
import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_CENTER;
44
import static org.mockito.Mockito.times;
@@ -8,8 +8,8 @@
88
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
99
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
1010

11-
import com.somemore.domains.center.dto.response.CenterProfileResponseDto;
12-
import com.somemore.domains.center.usecase.query.CenterQueryUseCase;
11+
import com.somemore.center.dto.response.CenterProfileResponseDto;
12+
import com.somemore.center.usecase.NEWCenterQueryUseCase;
1313
import com.somemore.global.exception.BadRequestException;
1414
import com.somemore.support.ControllerTestSupport;
1515
import java.util.List;
@@ -23,72 +23,70 @@
2323
class CenterQueryApiControllerTest extends ControllerTestSupport {
2424

2525
@MockBean
26-
protected CenterQueryUseCase centerQueryUseCase;
26+
protected NEWCenterQueryUseCase centerQueryUseCase;
2727

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

3131
@BeforeEach
3232
void setUp() {
33-
centerId = UUID.randomUUID();
33+
userId = UUID.randomUUID();
3434
responseDto = CenterProfileResponseDto.builder()
35-
.centerId(centerId)
35+
.id(userId) // id로 수정
36+
.userId(UUID.randomUUID()) // userId 추가
37+
.homepageUrl("http://example.com")
3638
.name("Test Center")
3739
.contactNumber("010-1234-5678")
3840
.imgUrl("http://example.com/image.jpg")
3941
.introduce("This is a test center.")
40-
.homepageLink("http://example.com")
41-
.preferItems(List.of())
42+
.preferItems(List.of()) // preferItems 추가
4243
.build();
4344
}
4445

45-
@DisplayName("기관 ID로 기관 프로필을 조회할 수 있다. (controller)")
46+
@DisplayName("유저 ID로 기관 유저 프로필을 조회할 수 있다. (controller)")
4647
@Test
4748
void getCenterProfile() throws Exception {
4849
// given
49-
when(centerQueryUseCase.getCenterProfileByCenterId(centerId)).thenReturn(responseDto);
50+
when(centerQueryUseCase.getCenterProfileByUserId(userId)).thenReturn(responseDto);
5051

51-
// when // then
52+
// when & then
5253
mockMvc.perform(
53-
get("/api/center/profile/{centerId}", centerId)
54+
get("/api/center/profile/{userId}", userId)
5455
.contentType(MediaType.APPLICATION_JSON)
5556
)
5657
.andExpect(status().isOk())
5758
.andExpect(jsonPath("$.code").value("200"))
5859
.andExpect(jsonPath("$.message").value("기관 프로필 조회 성공"))
59-
.andExpect(jsonPath("$.data.center_id").value(centerId.toString())) // center_id로 수정
60-
.andExpect(jsonPath("$.data.name").value("Test Center"))
61-
.andExpect(jsonPath("$.data.contact_number").value(
62-
"010-1234-5678")) // contact_number로 수정
63-
.andExpect(jsonPath("$.data.img_url").value(
64-
"http://example.com/image.jpg")) // img_url로 수정
65-
.andExpect(jsonPath("$.data.introduce").value("This is a test center."))
66-
.andExpect(jsonPath("$.data.homepage_link").value(
67-
"http://example.com")) // homepage_link로 수정
68-
.andExpect(jsonPath("$.data.prefer_items").isArray()); // prefer_items로 수정
60+
.andExpect(jsonPath("$.data.id").value(userId.toString()))
61+
.andExpect(jsonPath("$.data.user_id").value(responseDto.userId().toString()))
62+
.andExpect(jsonPath("$.data.homepage_url").value(responseDto.homepageUrl()))
63+
.andExpect(jsonPath("$.data.name").value(responseDto.name()))
64+
.andExpect(jsonPath("$.data.contact_number").value(responseDto.contactNumber()))
65+
.andExpect(jsonPath("$.data.img_url").value(responseDto.imgUrl()))
66+
.andExpect(jsonPath("$.data.introduce").value(responseDto.introduce()))
67+
.andExpect(jsonPath("$.data.prefer_items").isArray());
6968

70-
verify(centerQueryUseCase, times(1)).getCenterProfileByCenterId(centerId);
69+
verify(centerQueryUseCase, times(1)).getCenterProfileByUserId(userId);
7170
}
7271

73-
@DisplayName("존재하지 않는 기관 ID로 조회 시 예외가 발생한다. (controller)")
72+
@DisplayName("존재하지 않는 유저 ID로 조회 시 예외가 발생한다. (controller)")
7473
@Test
7574
void getCenterProfile_NotFound() throws Exception {
7675
// given
77-
UUID nonExistentCenterId = UUID.randomUUID();
78-
when(centerQueryUseCase.getCenterProfileByCenterId(nonExistentCenterId))
76+
UUID nonExistentuserId = UUID.randomUUID();
77+
when(centerQueryUseCase.getCenterProfileByUserId(nonExistentuserId))
7978
.thenThrow(new BadRequestException(NOT_EXISTS_CENTER.getMessage()));
8079

81-
// when // then
80+
// when & then
8281
mockMvc.perform(
83-
get("/api/center/profile/{centerId}", nonExistentCenterId)
82+
get("/api/center/profile/{userId}", nonExistentuserId)
8483
.contentType(MediaType.APPLICATION_JSON)
8584
)
8685
.andExpect(status().isBadRequest())
8786
.andExpect(jsonPath("$.status").value("400"))
8887
.andExpect(jsonPath("$.detail").value("존재하지 않는 기관입니다."));
8988

90-
verify(centerQueryUseCase, times(1)).getCenterProfileByCenterId(nonExistentCenterId);
89+
verify(centerQueryUseCase, times(1)).getCenterProfileByUserId(nonExistentuserId);
9190
}
9291

9392
}
94-

0 commit comments

Comments
 (0)