Skip to content

Commit 6240e12

Browse files
authored
Merge pull request #139 from ODOICHON/chore/template
[feature/board-service] 말머리에 따른 게시글 검색
2 parents b85302a + 62efb40 commit 6240e12

File tree

8 files changed

+302
-294
lines changed

8 files changed

+302
-294
lines changed

src/docs/asciidoc/board.adoc

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,25 @@ include::{snippets}/board-category/http-request.adoc[]
4848
===== Response
4949
include::{snippets}/board-category/http-response.adoc[]
5050

51-
==== 9. 게시글 검색
51+
==== 9. 게시글 검색 - 게시판 ( 자유 | 홍보 | 소개 )
52+
53+
본 API는 게시판별 게시글 목록 조회 기능을 수행합니다. name 값에 `DEFAULT`, `INTRO`, `ADVERTISEMENT` 값 중 하나를 입력해야 합니다.
54+
55+
keyword는 필수값은 아니며, 검색어를 통해 게시글의 작성자, 제목, 내용에 대해 검색합니다.
56+
57+
===== Request
58+
include::{snippets}/board-prefix-search/http-request.adoc[]
59+
===== Response
60+
include::{snippets}/board-prefix-search/http-response.adoc[]
61+
62+
===== 10.게시글 검색 - 말머리
63+
64+
본 API는 말머리별 게시글 목록 조회 기능을 수행합니다. name 값에 말머리 조회를 통해 얻은 code 데이터 중 하나를 입력해야 합니다.
65+
66+
keyword는 필수값은 아니며, 검색어를 통해 게시글의 작성자, 제목, 내용에 대해 검색합니다.
67+
5268
===== Request
53-
include::{snippets}/board-search/http-request.adoc[]
69+
include::{snippets}/board-category-search/http-request.adoc[]
70+
5471
===== Response
55-
include::{snippets}/board-search/http-response.adoc[]
72+
include::{snippets}/board-category-search/http-response.adoc[]

src/main/kotlin/com/example/jhouse_server/domain/board/controller/BoardController.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.example.jhouse_server.domain.board.controller
22

33
import com.example.jhouse_server.domain.board.*
44
import com.example.jhouse_server.domain.board.service.BoardService
5-
import com.example.jhouse_server.domain.user.entity.Authority
65
import com.example.jhouse_server.domain.user.entity.User
76
import com.example.jhouse_server.global.annotation.Auth
87
import com.example.jhouse_server.global.annotation.AuthUser
@@ -70,11 +69,20 @@ class BoardController(
7069
}
7170

7271
@GetMapping("/category/search")
73-
fun getBoardAllWithKeyword(
72+
fun getBoardAllWithPrefixCategory(
7473
@RequestParam name : String,
7574
@RequestParam keyword : String,
7675
pageable: Pageable
7776
) : ApplicationResponse<Page<BoardResDto>> {
78-
return ApplicationResponse.ok(boardService.getBoardAllWithKeyword(name, keyword, pageable));
77+
return ApplicationResponse.ok(boardService.getBoardAllWithPrefixCategory(name, keyword, pageable));
78+
}
79+
80+
@GetMapping("/board-category/search")
81+
fun getBoardAllWithBoardCategory(
82+
@RequestParam name : String,
83+
@RequestParam keyword : String,
84+
pageable: Pageable
85+
) : ApplicationResponse<Page<BoardResDto>> {
86+
return ApplicationResponse.ok(boardService.getBoardAllWithBoardCategory(name, keyword, pageable));
7987
}
8088
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
package com.example.jhouse_server.domain.board.repository
22

3-
import com.example.jhouse_server.admin.board.dto.AdminBoardDeleteList
43
import com.example.jhouse_server.admin.board.dto.AdminBoardSearch
54
import com.example.jhouse_server.domain.board.PrefixCategory
65
import com.example.jhouse_server.domain.board.entity.Board
6+
import com.example.jhouse_server.domain.board.entity.BoardCategory
77
import org.springframework.data.domain.Page
88
import org.springframework.data.domain.Pageable
99

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

1313
fun getDeletableBoardListWithPaging(adminBoardSearch: AdminBoardSearch, pageable: Pageable): Page<Board>
14-
fun getBoardAllWithKeyword(name: PrefixCategory, keyword: String, pageable: Pageable): Page<Board>
14+
fun getBoardAllWithPrefixCategory(name: PrefixCategory, keyword: String, pageable: Pageable): Page<Board>
15+
abstract fun getBoardAllWithBoardCategory(name: BoardCategory, keyword: String, pageable: Pageable): Page<Board>
1516

1617
}

src/main/kotlin/com/example/jhouse_server/domain/board/repository/BoardRepositoryImpl.kt

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package com.example.jhouse_server.domain.board.repository
22

3-
import com.example.jhouse_server.admin.board.dto.AdminBoardDeleteList
43
import com.example.jhouse_server.admin.board.dto.AdminBoardSearch
54
import com.example.jhouse_server.admin.board.dto.SearchFilter
65
import com.example.jhouse_server.domain.board.PrefixCategory
76
import com.example.jhouse_server.domain.board.entity.Board
7+
import com.example.jhouse_server.domain.board.entity.BoardCategory
88
import com.example.jhouse_server.domain.board.entity.QBoard.board
99
import com.example.jhouse_server.domain.user.entity.QUser.user
1010
import com.querydsl.core.types.dsl.BooleanExpression
@@ -50,17 +50,34 @@ class BoardRepositoryImpl(
5050
return PageableExecutionUtils.getPage(result, pageable) {countQuery.fetch().size.toLong()}
5151
}
5252

53-
override fun getBoardAllWithKeyword(name: PrefixCategory, keyword: String, pageable: Pageable): Page<Board> {
53+
override fun getBoardAllWithPrefixCategory(name: PrefixCategory, keyword: String, pageable: Pageable): Page<Board> {
5454
val result = jpaQueryFactory
5555
.select(board)
5656
.from(board)
57-
.where(searchWithCategory(name), searchWithFilter(keyword))
57+
.where(searchWithPrefixCategory(name), searchWithKeyword(keyword))
5858
.fetch()
5959
return PageImpl(result, pageable, result.size.toLong())
6060
}
6161

62+
override fun getBoardAllWithBoardCategory(
63+
name: BoardCategory,
64+
keyword: String,
65+
pageable: Pageable
66+
): Page<Board> {
67+
val result = jpaQueryFactory
68+
.select(board)
69+
.from(board)
70+
.where(searchWithBoardCategory(name), searchWithKeyword(keyword))
71+
.fetch()
72+
return PageImpl(result, pageable, result.size.toLong())
73+
}
74+
75+
private fun searchWithBoardCategory(name: BoardCategory): BooleanExpression? {
76+
return board.category.eq(name)
77+
}
78+
6279

63-
private fun searchWithFilter(keyword: String): BooleanExpression? {
80+
private fun searchWithKeyword(keyword: String): BooleanExpression? {
6481
return board.content.contains(keyword)
6582
.or(board.title.contains(keyword))
6683
.or(board.user.nickName.eq(keyword))
@@ -73,7 +90,7 @@ class BoardRepositoryImpl(
7390
else -> null
7491
}
7592
}
76-
private fun searchWithCategory(name: PrefixCategory) : BooleanExpression? {
93+
private fun searchWithPrefixCategory(name: PrefixCategory) : BooleanExpression? {
7794
return board.prefixCategory.eq(name)
7895
}
7996
}

src/main/kotlin/com/example/jhouse_server/domain/board/service/BoardService.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ interface BoardService {
1212
fun getBoardOne(boardId: Long): BoardResOneDto
1313
fun deleteBoard(boardId: Long, user: User)
1414
fun getCategory(name: String): List<CodeResDto>
15-
fun getBoardAllWithKeyword(name: String, keyword: String, pageable: Pageable): Page<BoardResDto>
15+
fun getBoardAllWithPrefixCategory(name: String, keyword: String, pageable: Pageable): Page<BoardResDto>
16+
abstract fun getBoardAllWithBoardCategory(name: String, keyword: String, pageable: Pageable): Page<BoardResDto>
1617

1718
}

src/main/kotlin/com/example/jhouse_server/domain/board/service/BoardServiceImpl.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,18 @@ class BoardServiceImpl(
7979
return BoardCategory.values().filter { it.superCategory.name == name }.map { CodeResDto(it.value, it.name) }
8080
}
8181

82-
override fun getBoardAllWithKeyword(name: String, keyword: String, pageable: Pageable): Page<BoardResDto> {
82+
override fun getBoardAllWithPrefixCategory(name: String, keyword: String, pageable: Pageable): Page<BoardResDto> {
8383
val prefixCategoryName = PrefixCategory.valueOf(name)
84-
return boardRepository.getBoardAllWithKeyword(prefixCategoryName, keyword, pageable).map { toListDto(it) }
84+
return boardRepository.getBoardAllWithPrefixCategory(prefixCategoryName, keyword, pageable).map { toListDto(it) }
85+
}
86+
87+
override fun getBoardAllWithBoardCategory(
88+
name: String,
89+
keyword: String,
90+
pageable: Pageable
91+
): Page<BoardResDto> {
92+
val boardCategoryName = BoardCategory.valueOf(name)
93+
return boardRepository.getBoardAllWithBoardCategory(boardCategoryName, keyword, pageable).map{ toListDto(it) }
8594
}
8695

8796
fun getContent(code: String): String {

0 commit comments

Comments
 (0)