From 53142f4688aa0da4c692e560a670e4633a1a0ce8 Mon Sep 17 00:00:00 2001 From: tori Date: Wed, 13 Dec 2023 18:05:51 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20=EA=B2=80?= =?UTF-8?q?=EC=83=89=20=EC=B2=98=EB=A6=AC=20(=ED=8E=98=EC=9D=B4=EC=A7=95?= =?UTF-8?q?=20=ED=8F=AC=ED=95=A8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/controller/BoardController.java | 13 ++++++ .../com/dearsanta/app/mapper/BoardMapper.java | 1 + .../dearsanta/app/service/BoardService.java | 1 + .../app/service/BoardServiceImpl.java | 13 ++++++ .../com/dearsanta/app/mapper/BoardMapper.xml | 46 +++++++++++++++++++ 5 files changed, 74 insertions(+) diff --git a/src/main/java/com/dearsanta/app/controller/BoardController.java b/src/main/java/com/dearsanta/app/controller/BoardController.java index 3d7fd4d..76e607e 100644 --- a/src/main/java/com/dearsanta/app/controller/BoardController.java +++ b/src/main/java/com/dearsanta/app/controller/BoardController.java @@ -148,6 +148,19 @@ public ResponseEntity getBoardListWithPaging( return ResponseEntity.status(HttpStatus.OK).body(boards); } + @GetMapping(value="/board") + public ResponseEntity 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 getBoardByMyPage( @RequestParam(value = "pageNum", defaultValue = "1") int pageNum, diff --git a/src/main/java/com/dearsanta/app/mapper/BoardMapper.java b/src/main/java/com/dearsanta/app/mapper/BoardMapper.java index da1ce6a..e02329d 100644 --- a/src/main/java/com/dearsanta/app/mapper/BoardMapper.java +++ b/src/main/java/com/dearsanta/app/mapper/BoardMapper.java @@ -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 getBoardListWithPagingByKeyword(@Param("criteria") Criteria criteria); } diff --git a/src/main/java/com/dearsanta/app/service/BoardService.java b/src/main/java/com/dearsanta/app/service/BoardService.java index 92072f2..25e036a 100644 --- a/src/main/java/com/dearsanta/app/service/BoardService.java +++ b/src/main/java/com/dearsanta/app/service/BoardService.java @@ -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); } diff --git a/src/main/java/com/dearsanta/app/service/BoardServiceImpl.java b/src/main/java/com/dearsanta/app/service/BoardServiceImpl.java index 09a24bb..4e87f92 100644 --- a/src/main/java/com/dearsanta/app/service/BoardServiceImpl.java +++ b/src/main/java/com/dearsanta/app/service/BoardServiceImpl.java @@ -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 boardDtos = boardMapper.getBoardListWithPagingByKeyword(criteria); + return new BoardListDto(boardDtos); + } } diff --git a/src/main/resources/com/dearsanta/app/mapper/BoardMapper.xml b/src/main/resources/com/dearsanta/app/mapper/BoardMapper.xml index 1de9a8a..c85d8d3 100644 --- a/src/main/resources/com/dearsanta/app/mapper/BoardMapper.xml +++ b/src/main/resources/com/dearsanta/app/mapper/BoardMapper.xml @@ -216,6 +216,52 @@ ]]> + + UPDATE board SET reply_count = reply_count + 1