Skip to content

Commit

Permalink
feat: 카테고리 목록 API 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
belljun3395 committed Jul 26, 2024
1 parent a134e54 commit 10e3e87
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ class WorkBookController(
private val readWorkbookUseCase: ReadWorkbookUseCase,
) {

@GetMapping("/categories")
fun browseWorkBookCategories(): ApiResponse<ApiResponse.SuccessBody<List<Map<String, String>>>> {
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)
Expand Down
14 changes: 7 additions & 7 deletions api/src/main/kotlin/com/few/api/web/support/WorkBookCategory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 10e3e87

Please sign in to comment.