-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/69 기관 프로필 조회 컨트롤러 구현 #74
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
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
32 changes: 32 additions & 0 deletions
32
src/main/java/com/somemore/center/controller/CenterQueryApiController.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,32 @@ | ||
| package com.somemore.center.controller; | ||
|
|
||
| import com.somemore.center.dto.response.CenterProfileResponseDto; | ||
| import com.somemore.center.usecase.query.CenterQueryUseCase; | ||
| import com.somemore.global.common.response.ApiResponse; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @RestController | ||
| @RequestMapping("/api/center") | ||
| @Tag(name = "Center Query API", description = "기관 관련 조회 API를 제공합니다.") | ||
| public class CenterQueryApiController { | ||
|
|
||
| private final CenterQueryUseCase centerQueryUseCase; | ||
|
|
||
| @Operation(summary = "기관 프로필 조회 API") | ||
| @GetMapping("/profile/{centerId}") | ||
| public ApiResponse<CenterProfileResponseDto> getCenterProfile(@PathVariable UUID centerId) { | ||
|
|
||
| CenterProfileResponseDto responseDto = centerQueryUseCase.getCenterProfileByCenterId(centerId); | ||
|
|
||
| return ApiResponse.ok(200, responseDto, "기관 프로필 조회 성공"); | ||
| } | ||
| } |
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
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
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
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,21 @@ | ||
| package com.somemore; | ||
|
|
||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.test.context.ActiveProfiles; | ||
| import org.springframework.test.web.servlet.MockMvc; | ||
|
|
||
| @ActiveProfiles("test") | ||
| @SpringBootTest | ||
| @AutoConfigureMockMvc | ||
| public abstract class ControllerTestSupport { | ||
|
|
||
| @Autowired | ||
| protected MockMvc mockMvc; | ||
|
|
||
| @Autowired | ||
| protected ObjectMapper objectMapper; | ||
| } |
93 changes: 93 additions & 0 deletions
93
src/test/java/com/somemore/center/controller/CenterQueryApiControllerTest.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,93 @@ | ||
| package com.somemore.center.controller; | ||
|
|
||
| import com.somemore.ControllerTestSupport; | ||
| import com.somemore.center.dto.response.CenterProfileResponseDto; | ||
| import com.somemore.center.usecase.query.CenterQueryUseCase; | ||
| import com.somemore.global.exception.BadRequestException; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.boot.test.mock.mockito.MockBean; | ||
| import org.springframework.http.MediaType; | ||
|
|
||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_CENTER; | ||
| import static org.mockito.Mockito.*; | ||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | ||
|
|
||
| class CenterQueryApiControllerTest extends ControllerTestSupport { | ||
|
|
||
| @MockBean | ||
| protected CenterQueryUseCase centerQueryUseCase; | ||
|
|
||
| private UUID centerId; | ||
| private CenterProfileResponseDto responseDto; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| centerId = UUID.randomUUID(); | ||
| responseDto = CenterProfileResponseDto.builder() | ||
| .centerId(centerId) | ||
| .name("Test Center") | ||
| .contactNumber("010-1234-5678") | ||
| .imgUrl("http://example.com/image.jpg") | ||
| .introduce("This is a test center.") | ||
| .homepageLink("http://example.com") | ||
| .preferItems(List.of()) | ||
| .build(); | ||
| } | ||
|
|
||
| @DisplayName("기관 ID로 기관 프로필을 조회할 수 있다. (controller)") | ||
| @Test | ||
| void getCenterProfile() throws Exception { | ||
| // given | ||
| when(centerQueryUseCase.getCenterProfileByCenterId(centerId)).thenReturn(responseDto); | ||
|
|
||
| // when // then | ||
| mockMvc.perform( | ||
| get("/api/center/profile/{centerId}", centerId) | ||
| .contentType(MediaType.APPLICATION_JSON) | ||
| ) | ||
| .andDo(print()) | ||
| .andExpect(status().isOk()) | ||
| .andExpect(jsonPath("$.code").value("200")) | ||
| .andExpect(jsonPath("$.message").value("기관 프로필 조회 성공")) | ||
| .andExpect(jsonPath("$.data.center_id").value(centerId.toString())) // center_id로 수정 | ||
| .andExpect(jsonPath("$.data.name").value("Test Center")) | ||
| .andExpect(jsonPath("$.data.contact_number").value("010-1234-5678")) // contact_number로 수정 | ||
| .andExpect(jsonPath("$.data.img_url").value("http://example.com/image.jpg")) // img_url로 수정 | ||
| .andExpect(jsonPath("$.data.introduce").value("This is a test center.")) | ||
| .andExpect(jsonPath("$.data.homepage_link").value("http://example.com")) // homepage_link로 수정 | ||
| .andExpect(jsonPath("$.data.prefer_items").isArray()); // prefer_items로 수정 | ||
|
|
||
| verify(centerQueryUseCase, times(1)).getCenterProfileByCenterId(centerId); | ||
| } | ||
|
|
||
| @DisplayName("존재하지 않는 기관 ID로 조회 시 예외가 발생한다. (controller)") | ||
| @Test | ||
| void getCenterProfile_NotFound() throws Exception { | ||
| // given | ||
| UUID nonExistentCenterId = UUID.randomUUID(); | ||
| when(centerQueryUseCase.getCenterProfileByCenterId(nonExistentCenterId)) | ||
| .thenThrow(new BadRequestException(NOT_EXISTS_CENTER.getMessage())); | ||
|
|
||
| // when // then | ||
| mockMvc.perform( | ||
| get("/api/center/profile/{centerId}", nonExistentCenterId) | ||
| .contentType(MediaType.APPLICATION_JSON) | ||
| ) | ||
| .andDo(print()) | ||
| .andExpect(status().isBadRequest()) | ||
| .andExpect(jsonPath("$.status").value("400")) | ||
| .andExpect(jsonPath("$.detail").value("존재하지 않는 기관 입니다.")); | ||
|
|
||
| verify(centerQueryUseCase, times(1)).getCenterProfileByCenterId(nonExistentCenterId); | ||
| } | ||
|
|
||
| } | ||
|
|
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.
이렇게 바꾸신 이유가 혹시 오류 떄문인가요?
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.
BINARY(16)으로 id값을 압축했다는걸 명시적으로 보여주고 싶었어요