From 10e3e8724bb4a1f520bdd76edd33651809a6a8c7 Mon Sep 17 00:00:00 2001 From: belljun3395 <195850@jnu.ac.kr> Date: Fri, 26 Jul 2024 16:53:29 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20API=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/workbook/WorkBookController.kt | 13 ++++++ .../few/api/web/support/WorkBookCategory.kt | 14 +++---- .../workbook/WorkBookControllerTest.kt | 42 +++++++++++++++++++ 3 files changed, 62 insertions(+), 7 deletions(-) diff --git a/api/src/main/kotlin/com/few/api/web/controller/workbook/WorkBookController.kt b/api/src/main/kotlin/com/few/api/web/controller/workbook/WorkBookController.kt index e22543aca..993fd73f5 100644 --- a/api/src/main/kotlin/com/few/api/web/controller/workbook/WorkBookController.kt +++ b/api/src/main/kotlin/com/few/api/web/controller/workbook/WorkBookController.kt @@ -29,6 +29,19 @@ class WorkBookController( private val readWorkbookUseCase: ReadWorkbookUseCase, ) { + @GetMapping("/categories") + fun browseWorkBookCategories(): ApiResponse>>> { + return ApiResponseGenerator.success( + WorkBookCategory.entries.map { + mapOf( + "parameterName" to it.parameterName, + "displayName" to it.displayName + ) + }, + HttpStatus.OK + ) + } + @GetMapping fun browseWorkBooks( @RequestParam(value = "category", required = false) diff --git a/api/src/main/kotlin/com/few/api/web/support/WorkBookCategory.kt b/api/src/main/kotlin/com/few/api/web/support/WorkBookCategory.kt index d868b12d5..3f7244540 100644 --- a/api/src/main/kotlin/com/few/api/web/support/WorkBookCategory.kt +++ b/api/src/main/kotlin/com/few/api/web/support/WorkBookCategory.kt @@ -4,13 +4,13 @@ package com.few.api.web.support * BatchCategoryType is origin from CategoryType in few-data module. * @see com.few.data.common.code.CategoryType */ -enum class WorkBookCategory(val code: Byte, val parameterName: String) { - All(-1, "all"), - ECONOMY(0, "economy"), - IT(10, "it"), - MARKETING(20, "marketing"), - CULTURE(30, "culture"), - SCIENCE(40, "science"), +enum class WorkBookCategory(val code: Byte, val parameterName: String, val displayName: String) { + All(-1, "all", "전체"), + ECONOMY(0, "economy", "경제"), + IT(10, "it", "IT"), + MARKETING(20, "marketing", "마케팅"), + CULTURE(30, "culture", "문화"), + SCIENCE(40, "science", "과학"), ; companion object { diff --git a/api/src/test/kotlin/com/few/api/web/controller/workbook/WorkBookControllerTest.kt b/api/src/test/kotlin/com/few/api/web/controller/workbook/WorkBookControllerTest.kt index 39c829e8d..91637af12 100644 --- a/api/src/test/kotlin/com/few/api/web/controller/workbook/WorkBookControllerTest.kt +++ b/api/src/test/kotlin/com/few/api/web/controller/workbook/WorkBookControllerTest.kt @@ -71,6 +71,48 @@ class WorkBookControllerTest : ControllerTestSpec() { .build() } + @Test + @DisplayName("[GET] /api/v1/workbooks/categories") + fun browseWorkBookCategories() { + // given + val api = "BrowseWorkBookCategories" + val uri = UriComponentsBuilder.newInstance() + .path("$BASE_URL/categories") + .build() + .toUriString() + + // when + mockMvc.perform( + get(uri) + .contentType(MediaType.APPLICATION_JSON) + ).andExpect( + status().is2xxSuccessful + ).andDo( + document( + api.toIdentifier(), + resource( + ResourceSnippetParameters.builder() + .summary(api.toIdentifier()) + .description("학습지 카테고리 목록을 조회합니다.") + .tag(TAG) + .responseSchema(Schema.schema(api.toResponseSchema())) + .responseFields( + *Description.describe( + arrayOf( + PayloadDocumentation.fieldWithPath("data[]") + .fieldWithArray("카테고리 정보"), + PayloadDocumentation.fieldWithPath("data[].parameterName") + .fieldWithString("카테고리 파라미터 이름"), + PayloadDocumentation.fieldWithPath("data[].displayName") + .fieldWithString("카테고리 표시 이름") + ) + ) + ).build() + ) + ) + ) + } + @Test @DisplayName("[GET] /api/v1/workbooks") fun browseWorkBooks() {