From 2dcf619c2fb80ea2717e75b659164dc8bf96be62 Mon Sep 17 00:00:00 2001 From: heoboseong7 Date: Sat, 3 Dec 2022 21:04:28 +0900 Subject: [PATCH] =?UTF-8?q?[Feat]=20=EC=9C=A0=EC=A0=80ID=EB=A1=9C=20?= =?UTF-8?q?=EC=84=9C=EB=9E=8D=20=EC=A1=B0=ED=9A=8C=20API,=20API=20Test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/insight/DrawerController.java | 5 +++ .../service/insight/DrawerApiService.java | 7 ++++ .../api/insight/DrawerControllerTest.java | 35 +++++++++++++++++++ 3 files changed, 47 insertions(+) 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() + ))); + } }