Skip to content

Commit

Permalink
Merge pull request #17 from LeeSM0518/DVK-61-apply-swagger-to-categor…
Browse files Browse the repository at this point in the history
…y-api

[DVK-61] fix: 카테고리 API에 Swagger 적용
  • Loading branch information
LeeSM0518 authored Nov 3, 2024
2 parents c482cf1 + 3b6f095 commit b633815
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,31 +1,21 @@
package com.devooks.backend.category.v1.controller

import com.devooks.backend.category.v1.dto.GetCategoriesRequest
import com.devooks.backend.category.v1.dto.GetCategoriesResponse
import com.devooks.backend.category.v1.dto.GetCategoriesResponse.Companion.toResponse
import com.devooks.backend.category.v1.service.CategoryService
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/api/v1/categories")
class CategoryController(
private val categoryService: CategoryService,
) {
): CategoryControllerDocs {

@GetMapping
suspend fun getCategories(
@RequestParam(required = false, defaultValue = "")
name: String,
@RequestParam(required = false, defaultValue = "")
page: String,
@RequestParam(required = false, defaultValue = "")
count: String,
): GetCategoriesResponse {
val request = GetCategoriesRequest(name, page, count)
return categoryService.get(request).toResponse()
override suspend fun getCategories(): GetCategoriesResponse {
return categoryService.getAll().toResponse()
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.devooks.backend.category.v1.controller

import com.devooks.backend.category.v1.dto.GetCategoriesResponse
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.responses.ApiResponse
import io.swagger.v3.oas.annotations.responses.ApiResponses
import io.swagger.v3.oas.annotations.tags.Tag

@Tag(name = "카테고리 API")
interface CategoryControllerDocs {

@Operation(summary = "카테고리 목록 조회")
@ApiResponses(value = [ApiResponse(responseCode = "200", description = "OK")])
suspend fun getCategories(): GetCategoriesResponse
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.devooks.backend.category.v1.service

import com.devooks.backend.category.v1.domain.Category
import com.devooks.backend.category.v1.domain.Category.Companion.toDomain
import com.devooks.backend.category.v1.dto.GetCategoriesRequest
import com.devooks.backend.category.v1.error.CategoryError
import com.devooks.backend.category.v1.repository.CategoryRepository
import java.util.*
Expand All @@ -16,12 +15,9 @@ class CategoryService(
private val categoryRepository: CategoryRepository,
) {

suspend fun get(request: GetCategoriesRequest): List<Category> =
suspend fun getAll(): List<Category> =
categoryRepository
.findAllByNameLikeIgnoreCase(
name = request.keyword,
pageable = request.paging.value
)
.findAll()
.map { it.toDomain() }
.toList()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ internal class CategoryControllerTest @Autowired constructor(
// when
val categories = webTestClient
.get()
.uri("/api/v1/categories?page=1&count=10")
.uri("/api/v1/categories")
.accept(APPLICATION_JSON)
.exchange()
.expectStatus().isOk
Expand Down

0 comments on commit b633815

Please sign in to comment.