Skip to content

Commit

Permalink
Merge pull request #140 from ODOICHON/dev
Browse files Browse the repository at this point in the history
main <- develop
  • Loading branch information
dldmsql authored May 2, 2023
2 parents 9bdd654 + 6240e12 commit f6faa0a
Show file tree
Hide file tree
Showing 8 changed files with 302 additions and 294 deletions.
23 changes: 20 additions & 3 deletions src/docs/asciidoc/board.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
include::{snippets}/board-category-search/http-response.adoc[]
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -70,11 +69,20 @@ class BoardController(
}

@GetMapping("/category/search")
fun getBoardAllWithKeyword(
fun getBoardAllWithPrefixCategory(
@RequestParam name : String,
@RequestParam keyword : String,
pageable: Pageable
) : ApplicationResponse<Page<BoardResDto>> {
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<Page<BoardResDto>> {
return ApplicationResponse.ok(boardService.getBoardAllWithBoardCategory(name, keyword, pageable));
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
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

interface BoardRepositoryCustom {
fun getFixableBoardListWithPaging(adminBoardSearch: AdminBoardSearch, pageable: Pageable): Page<Board>

fun getDeletableBoardListWithPaging(adminBoardSearch: AdminBoardSearch, pageable: Pageable): Page<Board>
fun getBoardAllWithKeyword(name: PrefixCategory, keyword: String, pageable: Pageable): Page<Board>
fun getBoardAllWithPrefixCategory(name: PrefixCategory, keyword: String, pageable: Pageable): Page<Board>
abstract fun getBoardAllWithBoardCategory(name: BoardCategory, keyword: String, pageable: Pageable): Page<Board>

}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<Board> {
override fun getBoardAllWithPrefixCategory(name: PrefixCategory, keyword: String, pageable: Pageable): Page<Board> {
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<Board> {
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))
Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface BoardService {
fun getBoardOne(boardId: Long): BoardResOneDto
fun deleteBoard(boardId: Long, user: User)
fun getCategory(name: String): List<CodeResDto>
fun getBoardAllWithKeyword(name: String, keyword: String, pageable: Pageable): Page<BoardResDto>
fun getBoardAllWithPrefixCategory(name: String, keyword: String, pageable: Pageable): Page<BoardResDto>
abstract fun getBoardAllWithBoardCategory(name: String, keyword: String, pageable: Pageable): Page<BoardResDto>

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<BoardResDto> {
override fun getBoardAllWithPrefixCategory(name: String, keyword: String, pageable: Pageable): Page<BoardResDto> {
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<BoardResDto> {
val boardCategoryName = BoardCategory.valueOf(name)
return boardRepository.getBoardAllWithBoardCategory(boardCategoryName, keyword, pageable).map{ toListDto(it) }
}

fun getContent(code: String): String {
Expand Down
Loading

0 comments on commit f6faa0a

Please sign in to comment.