-
Notifications
You must be signed in to change notification settings - Fork 0
[성능] Querydsl를 사용한 쿼리 통일화
YoonTaeMin edited this page Jun 4, 2023
·
5 revisions
게시글의 말머리(prefix category), 세부 카테고리(category), 그리고 사용자의 검색(keyword)에 대해서 각각의 api를 만들고, 쿼리를 작성하였습니다. 이는 3개의 api가 필요하고, 3개의 쿼리를 작성해야함을 의미합니다.
@GetMapping
fun getBoardAll(
@RequestParam category: String,
pageable: Pageable
) : ApplicationResponse<Page<BoardResDto>> {
return ApplicationResponse.ok(boardService.getBoardAll(category, pageable))
}
@GetMapping("/category/search")
fun getBoardAllWithPrefixCategory(
@RequestParam name : String,
@RequestParam keyword : String,
pageable: Pageable
) : ApplicationResponse<Page<BoardResDto>> {
return ApplicationResponse.ok(boardService.getBoardAllWithPrefixCategory(name, keyword, pageable));
}
@GetMapping("/board-category/search")
fun getBoardAllWithBoardCategory(
@RequestParam name : String,
@RequestParam keyword : String,
pageable: Pageable
) : ApplicationResponse<Page<BoardResDto>> {
return ApplicationResponse.ok(boardService.getBoardAllWithBoardCategory(name, keyword, pageable));
}
Querydsl을 사용하여 검색조건에 따른 세가지의 쿼리를 하나의 쿼리로 통일하였습니다. 추가적으로 요청에 필요한 쿼리파라미터의 수가 많기 때문에, @ModelAttribute를 사용하여 한번에 묶어서 관리하였습니다.
@GetMapping
fun getBoardAll(
@ModelAttribute boardListDto: BoardListDto,
@PageableDefault(size=8, page=0) pageable: Pageable
): ApplicationResponse<Page<BoardResDto>> {
return ApplicationResponse.ok(boardService.getBoardAll(boardListDto, pageable))
}
불필요한 api의 수를 줄일 수 있고, 요청을 보내는 uri가 통일되어 있다보니, 프론트엔드 개발자분이 조금 더 개발하기 수월해졌다고 의견을 주셨습니다!