diff --git a/src/docs/asciidoc/board.adoc b/src/docs/asciidoc/board.adoc index ca040182..ad28170e 100644 --- a/src/docs/asciidoc/board.adoc +++ b/src/docs/asciidoc/board.adoc @@ -48,8 +48,25 @@ include::{snippets}/board-category/http-request.adoc[] ===== Response include::{snippets}/board-category/http-response.adoc[] -==== 9. 게시글 검색 +==== 9. 게시글 검색 - 게시판 ( 자유 | 홍보 | 소개 ) + +본 API는 게시판별 게시글 목록 조회 기능을 수행합니다. name 값에 `DEFAULT`, `INTRO`, `ADVERTISEMENT` 값 중 하나를 입력해야 합니다. + +keyword는 필수값은 아니며, 검색어를 통해 게시글의 작성자, 제목, 내용에 대해 검색합니다. + +===== Request +include::{snippets}/board-prefix-search/http-request.adoc[] +===== Response +include::{snippets}/board-prefix-search/http-response.adoc[] + +===== 10.게시글 검색 - 말머리 + +본 API는 말머리별 게시글 목록 조회 기능을 수행합니다. name 값에 말머리 조회를 통해 얻은 code 데이터 중 하나를 입력해야 합니다. + +keyword는 필수값은 아니며, 검색어를 통해 게시글의 작성자, 제목, 내용에 대해 검색합니다. + ===== Request -include::{snippets}/board-search/http-request.adoc[] +include::{snippets}/board-category-search/http-request.adoc[] + ===== Response -include::{snippets}/board-search/http-response.adoc[] \ No newline at end of file +include::{snippets}/board-category-search/http-response.adoc[] \ No newline at end of file diff --git a/src/main/kotlin/com/example/jhouse_server/domain/board/controller/BoardController.kt b/src/main/kotlin/com/example/jhouse_server/domain/board/controller/BoardController.kt index 071ceb5f..6daa083f 100644 --- a/src/main/kotlin/com/example/jhouse_server/domain/board/controller/BoardController.kt +++ b/src/main/kotlin/com/example/jhouse_server/domain/board/controller/BoardController.kt @@ -2,7 +2,6 @@ package com.example.jhouse_server.domain.board.controller import com.example.jhouse_server.domain.board.* import com.example.jhouse_server.domain.board.service.BoardService -import com.example.jhouse_server.domain.user.entity.Authority import com.example.jhouse_server.domain.user.entity.User import com.example.jhouse_server.global.annotation.Auth import com.example.jhouse_server.global.annotation.AuthUser @@ -70,11 +69,20 @@ class BoardController( } @GetMapping("/category/search") - fun getBoardAllWithKeyword( + fun getBoardAllWithPrefixCategory( @RequestParam name : String, @RequestParam keyword : String, pageable: Pageable ) : ApplicationResponse> { - return ApplicationResponse.ok(boardService.getBoardAllWithKeyword(name, keyword, pageable)); + return ApplicationResponse.ok(boardService.getBoardAllWithPrefixCategory(name, keyword, pageable)); + } + + @GetMapping("/board-category/search") + fun getBoardAllWithBoardCategory( + @RequestParam name : String, + @RequestParam keyword : String, + pageable: Pageable + ) : ApplicationResponse> { + return ApplicationResponse.ok(boardService.getBoardAllWithBoardCategory(name, keyword, pageable)); } } \ No newline at end of file diff --git a/src/main/kotlin/com/example/jhouse_server/domain/board/repository/BoardRepositoryCustom.kt b/src/main/kotlin/com/example/jhouse_server/domain/board/repository/BoardRepositoryCustom.kt index 71e21a89..c8f9754e 100644 --- a/src/main/kotlin/com/example/jhouse_server/domain/board/repository/BoardRepositoryCustom.kt +++ b/src/main/kotlin/com/example/jhouse_server/domain/board/repository/BoardRepositoryCustom.kt @@ -1,9 +1,9 @@ package com.example.jhouse_server.domain.board.repository -import com.example.jhouse_server.admin.board.dto.AdminBoardDeleteList import com.example.jhouse_server.admin.board.dto.AdminBoardSearch import com.example.jhouse_server.domain.board.PrefixCategory import com.example.jhouse_server.domain.board.entity.Board +import com.example.jhouse_server.domain.board.entity.BoardCategory import org.springframework.data.domain.Page import org.springframework.data.domain.Pageable @@ -11,6 +11,7 @@ interface BoardRepositoryCustom { fun getFixableBoardListWithPaging(adminBoardSearch: AdminBoardSearch, pageable: Pageable): Page fun getDeletableBoardListWithPaging(adminBoardSearch: AdminBoardSearch, pageable: Pageable): Page - fun getBoardAllWithKeyword(name: PrefixCategory, keyword: String, pageable: Pageable): Page + fun getBoardAllWithPrefixCategory(name: PrefixCategory, keyword: String, pageable: Pageable): Page + abstract fun getBoardAllWithBoardCategory(name: BoardCategory, keyword: String, pageable: Pageable): Page } \ No newline at end of file diff --git a/src/main/kotlin/com/example/jhouse_server/domain/board/repository/BoardRepositoryImpl.kt b/src/main/kotlin/com/example/jhouse_server/domain/board/repository/BoardRepositoryImpl.kt index 038918d3..5a263991 100644 --- a/src/main/kotlin/com/example/jhouse_server/domain/board/repository/BoardRepositoryImpl.kt +++ b/src/main/kotlin/com/example/jhouse_server/domain/board/repository/BoardRepositoryImpl.kt @@ -1,10 +1,10 @@ package com.example.jhouse_server.domain.board.repository -import com.example.jhouse_server.admin.board.dto.AdminBoardDeleteList import com.example.jhouse_server.admin.board.dto.AdminBoardSearch import com.example.jhouse_server.admin.board.dto.SearchFilter import com.example.jhouse_server.domain.board.PrefixCategory import com.example.jhouse_server.domain.board.entity.Board +import com.example.jhouse_server.domain.board.entity.BoardCategory import com.example.jhouse_server.domain.board.entity.QBoard.board import com.example.jhouse_server.domain.user.entity.QUser.user import com.querydsl.core.types.dsl.BooleanExpression @@ -50,17 +50,34 @@ class BoardRepositoryImpl( return PageableExecutionUtils.getPage(result, pageable) {countQuery.fetch().size.toLong()} } - override fun getBoardAllWithKeyword(name: PrefixCategory, keyword: String, pageable: Pageable): Page { + override fun getBoardAllWithPrefixCategory(name: PrefixCategory, keyword: String, pageable: Pageable): Page { val result = jpaQueryFactory .select(board) .from(board) - .where(searchWithCategory(name), searchWithFilter(keyword)) + .where(searchWithPrefixCategory(name), searchWithKeyword(keyword)) .fetch() return PageImpl(result, pageable, result.size.toLong()) } + override fun getBoardAllWithBoardCategory( + name: BoardCategory, + keyword: String, + pageable: Pageable + ): Page { + val result = jpaQueryFactory + .select(board) + .from(board) + .where(searchWithBoardCategory(name), searchWithKeyword(keyword)) + .fetch() + return PageImpl(result, pageable, result.size.toLong()) + } + + private fun searchWithBoardCategory(name: BoardCategory): BooleanExpression? { + return board.category.eq(name) + } + - private fun searchWithFilter(keyword: String): BooleanExpression? { + private fun searchWithKeyword(keyword: String): BooleanExpression? { return board.content.contains(keyword) .or(board.title.contains(keyword)) .or(board.user.nickName.eq(keyword)) @@ -73,7 +90,7 @@ class BoardRepositoryImpl( else -> null } } - private fun searchWithCategory(name: PrefixCategory) : BooleanExpression? { + private fun searchWithPrefixCategory(name: PrefixCategory) : BooleanExpression? { return board.prefixCategory.eq(name) } } \ No newline at end of file diff --git a/src/main/kotlin/com/example/jhouse_server/domain/board/service/BoardService.kt b/src/main/kotlin/com/example/jhouse_server/domain/board/service/BoardService.kt index d769172c..f118e697 100644 --- a/src/main/kotlin/com/example/jhouse_server/domain/board/service/BoardService.kt +++ b/src/main/kotlin/com/example/jhouse_server/domain/board/service/BoardService.kt @@ -12,6 +12,7 @@ interface BoardService { fun getBoardOne(boardId: Long): BoardResOneDto fun deleteBoard(boardId: Long, user: User) fun getCategory(name: String): List - fun getBoardAllWithKeyword(name: String, keyword: String, pageable: Pageable): Page + fun getBoardAllWithPrefixCategory(name: String, keyword: String, pageable: Pageable): Page + abstract fun getBoardAllWithBoardCategory(name: String, keyword: String, pageable: Pageable): Page } \ No newline at end of file diff --git a/src/main/kotlin/com/example/jhouse_server/domain/board/service/BoardServiceImpl.kt b/src/main/kotlin/com/example/jhouse_server/domain/board/service/BoardServiceImpl.kt index 0e847b31..94bce41b 100644 --- a/src/main/kotlin/com/example/jhouse_server/domain/board/service/BoardServiceImpl.kt +++ b/src/main/kotlin/com/example/jhouse_server/domain/board/service/BoardServiceImpl.kt @@ -79,9 +79,18 @@ class BoardServiceImpl( return BoardCategory.values().filter { it.superCategory.name == name }.map { CodeResDto(it.value, it.name) } } - override fun getBoardAllWithKeyword(name: String, keyword: String, pageable: Pageable): Page { + override fun getBoardAllWithPrefixCategory(name: String, keyword: String, pageable: Pageable): Page { val prefixCategoryName = PrefixCategory.valueOf(name) - return boardRepository.getBoardAllWithKeyword(prefixCategoryName, keyword, pageable).map { toListDto(it) } + return boardRepository.getBoardAllWithPrefixCategory(prefixCategoryName, keyword, pageable).map { toListDto(it) } + } + + override fun getBoardAllWithBoardCategory( + name: String, + keyword: String, + pageable: Pageable + ): Page { + val boardCategoryName = BoardCategory.valueOf(name) + return boardRepository.getBoardAllWithBoardCategory(boardCategoryName, keyword, pageable).map{ toListDto(it) } } fun getContent(code: String): String { diff --git a/src/main/resources/static/docs/board.html b/src/main/resources/static/docs/board.html index 0e13c267..47c1f4f2 100644 --- a/src/main/resources/static/docs/board.html +++ b/src/main/resources/static/docs/board.html @@ -4,23 +4,25 @@ - + Board API