Skip to content
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

[Feat] 유저의 서랍 목록 조회 #158

Merged
merged 1 commit into from
Dec 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@ public ApiResponse<DrawerCreateResponse> create(@RequestBody @Valid DrawerCreate
public ApiResponse<List<DrawerResponse>> getMyDrawers() {
return ApiResponse.ok(drawerApiService.getMyDrawers());
}

@GetMapping("/{userId}")
public ApiResponse<List<DrawerResponse>> getDrawers(@PathVariable Long userId) {
return ApiResponse.ok(drawerApiService.getDrawers(userId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,11 @@ public List<DrawerResponse> getMyDrawers() {
.map(insightAssembler::toDrawerResponse)
.collect(Collectors.toList());
}

@Transactional(readOnly = true)
public List<DrawerResponse> getDrawers(Long userId) {
return drawerDomainService.findAllByUserId(userId).stream()
.map(insightAssembler::toDrawerResponse)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<DrawerResponse> 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()
)));
}
}