diff --git a/keewe-api/src/main/java/ccc/keeweapi/api/insight/DrawerController.java b/keewe-api/src/main/java/ccc/keeweapi/api/insight/DrawerController.java index d5788a8d..ecb8b83c 100644 --- a/keewe-api/src/main/java/ccc/keeweapi/api/insight/DrawerController.java +++ b/keewe-api/src/main/java/ccc/keeweapi/api/insight/DrawerController.java @@ -27,4 +27,9 @@ public ApiResponse create(@RequestBody @Valid DrawerCreate public ApiResponse> getMyDrawers() { return ApiResponse.ok(drawerApiService.getMyDrawers()); } + + @GetMapping("/{userId}") + public ApiResponse> getDrawers(@PathVariable Long userId) { + return ApiResponse.ok(drawerApiService.getDrawers(userId)); + } } diff --git a/keewe-api/src/main/java/ccc/keeweapi/service/insight/DrawerApiService.java b/keewe-api/src/main/java/ccc/keeweapi/service/insight/DrawerApiService.java index 94f7ddaf..fd4c74e1 100644 --- a/keewe-api/src/main/java/ccc/keeweapi/service/insight/DrawerApiService.java +++ b/keewe-api/src/main/java/ccc/keeweapi/service/insight/DrawerApiService.java @@ -36,4 +36,11 @@ public List getMyDrawers() { .map(insightAssembler::toDrawerResponse) .collect(Collectors.toList()); } + + @Transactional(readOnly = true) + public List getDrawers(Long userId) { + return drawerDomainService.findAllByUserId(userId).stream() + .map(insightAssembler::toDrawerResponse) + .collect(Collectors.toList()); + } } diff --git a/keewe-api/src/test/java/ccc/keeweapi/api/insight/DrawerControllerTest.java b/keewe-api/src/test/java/ccc/keeweapi/api/insight/DrawerControllerTest.java index 8764bcc7..985239f6 100644 --- a/keewe-api/src/test/java/ccc/keeweapi/api/insight/DrawerControllerTest.java +++ b/keewe-api/src/test/java/ccc/keeweapi/api/insight/DrawerControllerTest.java @@ -105,4 +105,39 @@ void get_my_drawers_test() throws Exception { .build() ))); } + + @Test + @DisplayName("유저의 서랍 조회 API") + void get_drawers_test() throws Exception { + + Long userId = 1L; + + List responses = List.of( + DrawerResponse.of(1L, "개발"), + DrawerResponse.of(2L, "공부"), + DrawerResponse.of(3L, "디자인") + ); + + when(drawerApiService.getDrawers(userId)).thenReturn(responses); + + ResultActions resultActions = mockMvc.perform(get("/api/v1/drawer/{userId}", userId) + .header(HttpHeaders.AUTHORIZATION, "Bearer " + JWT) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + + resultActions.andDo(restDocs.document(resource( + ResourceSnippetParameters.builder() + .description("유저의 서랍 조회 API 입니다.") + .summary("유저의 서랍 조회 API") + .requestHeaders( + headerWithName("Authorization").description("유저의 JWT")) + .responseFields( + fieldWithPath("message").description("요청 결과 메세지"), + fieldWithPath("code").description("결과 코드"), + fieldWithPath("data.[].id").description("서랍의 ID"), + fieldWithPath("data.[].name").description("서랍의 이름")) + .tag("Insight") + .build() + ))); + } }