From 5609c5ced723cacc08e2059fa9900470698c6b12 Mon Sep 17 00:00:00 2001 From: MAVOTUNA Date: Tue, 23 Aug 2022 16:38:32 +0900 Subject: [PATCH] #92 DAILYLIFE2-46 by dm 2022.08.23 --- .../board/controller/BoardController.java | 6 +-- .../domain/board/service/BoardService.java | 2 +- .../board/service/BoardServiceImpl.java | 47 +++++++++++++------ .../com/dailylife/global/web/WebConfig.java | 3 +- 4 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/dailylife/domain/board/controller/BoardController.java b/src/main/java/com/dailylife/domain/board/controller/BoardController.java index 694406a..ae70242 100644 --- a/src/main/java/com/dailylife/domain/board/controller/BoardController.java +++ b/src/main/java/com/dailylife/domain/board/controller/BoardController.java @@ -11,6 +11,7 @@ import org.springframework.http.*; import org.springframework.web.bind.annotation.*; +import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; import java.io.IOException; import java.util.List; @@ -43,9 +44,8 @@ public ResponseEntity deleteBoard(@PathVariable("boardNum")Long boardNu } @ApiOperation(value = "페이징 게시글 가져오기", notes = "한 페이지 당 15개 게시글 가져옴, queryString 사용하여 pg(몇 페이지)는 필수로 넘겨주시고 query(검색어)는 있으면 채워서 보내주시면 됩니다(선택)") @GetMapping("/getBoard") - public ResponseEntity> list(@RequestParam(value = "pg", defaultValue = "1") int pg,@RequestParam(value = "keyword",defaultValue = "") String keyword, BoardPagination pagination) { - System.out.println(pagination.getKeyword()); - return ResponseEntity.ok(boardService.getPage(pagination)); + public ResponseEntity> list(@RequestParam(value = "pg", defaultValue = "1") int pg, @RequestParam(value = "keyword",defaultValue = "") String keyword, BoardPagination pagination , HttpServletRequest httpServletRequest) { + return ResponseEntity.ok(boardService.getPage(pagination , httpServletRequest.getHeader("X-ACCESS-TOKEN"))); } @ApiOperation(value = "전체 게시글 수 가져오기", notes = "등록된 게시물 수 가져오기") diff --git a/src/main/java/com/dailylife/domain/board/service/BoardService.java b/src/main/java/com/dailylife/domain/board/service/BoardService.java index 4bbe7fa..488e2f7 100644 --- a/src/main/java/com/dailylife/domain/board/service/BoardService.java +++ b/src/main/java/com/dailylife/domain/board/service/BoardService.java @@ -14,7 +14,7 @@ public interface BoardService { boolean delete(Long boardNum); - List getPage(BoardPagination pagination); + List getPage(BoardPagination pagination , String token); int getBoardCount(); diff --git a/src/main/java/com/dailylife/domain/board/service/BoardServiceImpl.java b/src/main/java/com/dailylife/domain/board/service/BoardServiceImpl.java index 341b622..03c0e1b 100644 --- a/src/main/java/com/dailylife/domain/board/service/BoardServiceImpl.java +++ b/src/main/java/com/dailylife/domain/board/service/BoardServiceImpl.java @@ -79,23 +79,40 @@ public boolean delete(Long boardNum) { } @Override - public List getPage(BoardPagination pagination) { - String loginId = jwtService.getLoginId(); - User user = userRepository.findByUserId(loginId); - Long uno = user.getUserNum(); - List BoardCreateAndGetResponseList = new ArrayList<>(); - for (Board board : paginationRepository.findAll(pagination)) { - - List serverFileUrl = new ArrayList<>(); - List imageNameList = new ArrayList<>(); - List byBoardBoardNum = imageRepository.findByBoardBoardNum(board.getBoardNum()); - for (Image image : byBoardBoardNum) { - imageNameList.add(image.getImageName()); - serverFileUrl.add(ServerUrl+image.getImageName()); + public List getPage(BoardPagination pagination , String token) { + List BoardCreateAndGetResponseList; + if(token != null) { + String loginId = jwtService.getLoginId(); + User user = userRepository.findByUserId(loginId); + Long uno = user.getUserNum(); + BoardCreateAndGetResponseList = new ArrayList<>(); + for (Board board : paginationRepository.findAll(pagination)) { + List serverFileUrl = new ArrayList<>(); + List imageNameList = new ArrayList<>(); + List byBoardBoardNum = imageRepository.findByBoardBoardNum(board.getBoardNum()); + for (Image image : byBoardBoardNum) { + imageNameList.add(image.getImageName()); + serverFileUrl.add(ServerUrl+image.getImageName()); + } + BoardCreateAndGetResponseList.add(BoardCreateAndGetResponse.from(board , imageNameList , serverFileUrl,heartService.getHeart(uno, board.getBoardNum()))); + } + return BoardCreateAndGetResponseList; + } + else { + BoardCreateAndGetResponseList= new ArrayList<>(); + for (Board board : paginationRepository.findAll(pagination)) { + List serverFileUrl = new ArrayList<>(); + List imageNameList = new ArrayList<>(); + List byBoardBoardNum = imageRepository.findByBoardBoardNum(board.getBoardNum()); + for (Image image : byBoardBoardNum) { + imageNameList.add(image.getImageName()); + serverFileUrl.add(ServerUrl+image.getImageName()); + } + BoardCreateAndGetResponseList.add(BoardCreateAndGetResponse.from(board , imageNameList , serverFileUrl, false)); } - BoardCreateAndGetResponseList.add(BoardCreateAndGetResponse.from(board , imageNameList , serverFileUrl,heartService.getHeart(uno, board.getBoardNum()))); + return BoardCreateAndGetResponseList; } - return BoardCreateAndGetResponseList; + } @Override diff --git a/src/main/java/com/dailylife/global/web/WebConfig.java b/src/main/java/com/dailylife/global/web/WebConfig.java index d76bfea..c2c87c1 100644 --- a/src/main/java/com/dailylife/global/web/WebConfig.java +++ b/src/main/java/com/dailylife/global/web/WebConfig.java @@ -52,7 +52,8 @@ public void addInterceptors(InterceptorRegistry registry) { "/boardImg/**", "/api/board/getBoardCount", "/api/heart/countHeartReply/**", - "/api/heart/countHeartBoard/**"); + "/api/heart/countHeartBoard/**" + ,"/api/board/getBoard"); }