Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 게시글 검색 처리 (페이징 포함) #34

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/main/java/com/dearsanta/app/controller/BoardController.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,19 @@ public ResponseEntity<BoardListDto> getBoardListWithPaging(
return ResponseEntity.status(HttpStatus.OK).body(boards);
}

@GetMapping(value="/board")
public ResponseEntity<BoardListDto> getBoardListWithPagingByKeyword (
@RequestParam(value = "keyword", defaultValue = "") String keyword,
@RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
@RequestParam(value = "pageSize", defaultValue = "5") int pageSize,
@RequestParam(value = "sorted", defaultValue = "LATEST") Sorted sorted
) {
BoardListDto boards = boardService.getBoardListWithPagingByKeyword(keyword, pageNum, pageSize, sorted);
log.info("getBoardListWithPagingByKeyword " + LocalDateTime.now());
log.info("keyword : " + keyword);
return ResponseEntity.status(HttpStatus.OK).body(boards);
}

@GetMapping("/auth/board")
public ResponseEntity<BoardListDto> getBoardByMyPage(
@RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/dearsanta/app/mapper/BoardMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ public interface BoardMapper {
void boardLike(BoardLikeDto boardLikeDto);
void boardUnlike(String likeId);
String findLikeId(@Param("boardId") String boardId, @Param("userId") String userId);
List<BoardDto> getBoardListWithPagingByKeyword(@Param("criteria") Criteria criteria);
}
1 change: 1 addition & 0 deletions src/main/java/com/dearsanta/app/service/BoardService.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ public interface BoardService {

void likeBoard(BoardLikeDto boardLikeDto);
void unlikeBoard(BoardLikeDto boardLikeDto);
BoardListDto getBoardListWithPagingByKeyword(String keyword, int pageNum, int pageSize, Sorted sorted);
}
13 changes: 13 additions & 0 deletions src/main/java/com/dearsanta/app/service/BoardServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,17 @@ public void unlikeBoard(BoardLikeDto boardLikeDto) {
boardMapper.boardUnlike(likeId);
boardMapper.decreaseLikeCount(board.getId());
}

@Override
public BoardListDto getBoardListWithPagingByKeyword(String keyword, int pageNum, int pageSize, Sorted sorted) {
Criteria criteria = Criteria.builder()
.selectId(keyword)
.pageNum(pageNum)
.pageSize(pageSize)
.sorted(sorted.getIndexColumn())
.build();

List<BoardDto> boardDtos = boardMapper.getBoardListWithPagingByKeyword(criteria);
return new BoardListDto(boardDtos);
}
}
46 changes: 46 additions & 0 deletions src/main/resources/com/dearsanta/app/mapper/BoardMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,52 @@
]]>
</select>

<select id="getBoardListWithPagingByKeyword" parameterType="com.dearsanta.app.dto.Criteria" resultType="com.dearsanta.app.dto.BoardDto">
<![CDATA[
SELECT
id,
title,
content,
createdDate,
updatedDate,
userId,
userNickname,
userImgUrl,
isMine,
imgUrl,
likeCount,
viewCount,
replyCount
FROM
(
SELECT /*+ INDEX_DESC(board ${criteria.sorted}) */
rownum AS rn,
board.id,
board.title,
board.content,
board.created_date AS createdDate,
board.updated_date AS updatedDate,
board.user_id AS userId,
member.nickname AS userNickname,
member.img_url AS userImgUrl,
0 AS isMine,
board.img_url AS imgUrl,
board.like_count AS likeCount,
board.view_count AS viewCount,
board.reply_count AS replyCount
FROM board
LEFT JOIN member
ON board.user_id = member.id
WHERE (board.title LIKE '%' || #{criteria.selectId} || '%'
OR board.content LIKE '%' || #{criteria.selectId} || '%')
AND board.is_deleted = 0
AND rownum <= #{criteria.pageNum} * #{criteria.pageSize}
)
WHERE rn > (#{criteria.pageNum} - 1) * #{criteria.pageSize}
]]>

</select>

<update id="increaseReplyCount" parameterType="java.lang.String">
UPDATE board
SET reply_count = reply_count + 1
Expand Down
Loading