From 062ff38ebf35a0b08fb6b8f8d25bf7b96a186d41 Mon Sep 17 00:00:00 2001 From: MAVOTUNA Date: Wed, 24 Aug 2022 15:17:59 +0900 Subject: [PATCH] #100 DAILYLIFE2-51 by dm --- .../board/controller/BoardController.java | 11 +++- .../domain/board/dto/BoardCreateRequest.java | 6 +- .../domain/board/service/BoardService.java | 3 +- .../board/service/BoardServiceImpl.java | 60 ++++++++++--------- .../heart/controller/HeartController.java | 3 - .../heart/service/HeartServiceImpl.java | 10 +++- .../domain/image/service/FileServiceImpl.java | 1 - .../com/dailylife/global/init/InitDB.java | 5 ++ .../global/jwt/service/JwtServiceImpl.java | 1 - .../com/dailylife/global/web/WebConfig.java | 2 +- 10 files changed, 58 insertions(+), 44 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 ae70242..2d5bcf6 100644 --- a/src/main/java/com/dailylife/domain/board/controller/BoardController.java +++ b/src/main/java/com/dailylife/domain/board/controller/BoardController.java @@ -42,10 +42,17 @@ public ResponseEntity deleteBoard(@PathVariable("boardNum")Long boardNu return ResponseEntity.ok(boardService.delete(boardNum)); } + + @ApiOperation(value = "페이징 게시글 가져오기 (비로그인용)", notes = "페이징 게시글 가져오기 (비로그인용)") + @GetMapping("/getBoardNotLogin") + public ResponseEntity> boardList(@RequestParam(value = "pg", defaultValue = "1") int pg, @RequestParam(value = "keyword",defaultValue = "") String keyword, BoardPagination pagination) { + return ResponseEntity.ok(boardService.getPageNotLogin(pagination)); + } + @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 , HttpServletRequest httpServletRequest) { - return ResponseEntity.ok(boardService.getPage(pagination , httpServletRequest.getHeader("X-ACCESS-TOKEN"))); + public ResponseEntity> list(@RequestParam(value = "pg", defaultValue = "1") int pg, @RequestParam(value = "keyword",defaultValue = "") String keyword, BoardPagination pagination) { + return ResponseEntity.ok(boardService.getPage(pagination)); } @ApiOperation(value = "전체 게시글 수 가져오기", notes = "등록된 게시물 수 가져오기") diff --git a/src/main/java/com/dailylife/domain/board/dto/BoardCreateRequest.java b/src/main/java/com/dailylife/domain/board/dto/BoardCreateRequest.java index f46c07b..c8c2951 100644 --- a/src/main/java/com/dailylife/domain/board/dto/BoardCreateRequest.java +++ b/src/main/java/com/dailylife/domain/board/dto/BoardCreateRequest.java @@ -2,10 +2,7 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; import org.springframework.web.multipart.MultipartFile; import javax.validation.constraints.NotBlank; @@ -15,6 +12,7 @@ @AllArgsConstructor @NoArgsConstructor @ApiModel(description = "게시물 생성을 위한 요청 객체") +@Builder public class BoardCreateRequest { @NotBlank(message = "게시물 제목을 입력해주세요") 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 488e2f7..67973df 100644 --- a/src/main/java/com/dailylife/domain/board/service/BoardService.java +++ b/src/main/java/com/dailylife/domain/board/service/BoardService.java @@ -14,10 +14,11 @@ public interface BoardService { boolean delete(Long boardNum); - List getPage(BoardPagination pagination , String token); + List getPage(BoardPagination pagination); int getBoardCount(); List TitleList(BoardPagination pagination); + List getPageNotLogin(BoardPagination pagination); } 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 03c0e1b..520149f 100644 --- a/src/main/java/com/dailylife/domain/board/service/BoardServiceImpl.java +++ b/src/main/java/com/dailylife/domain/board/service/BoardServiceImpl.java @@ -79,42 +79,44 @@ public boolean delete(Long boardNum) { } @Override - public List getPage(BoardPagination pagination , String token) { + public List getPage(BoardPagination pagination) { 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()))); + 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()); } - return BoardCreateAndGetResponseList; + BoardCreateAndGetResponseList.add(BoardCreateAndGetResponse.from(board , imageNameList , serverFileUrl,heartService.getHeart(uno, board.getBoardNum()))); } - 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)); + return BoardCreateAndGetResponseList; + } + + @Override + public List getPageNotLogin(BoardPagination pagination) { + List BoardCreateAndGetResponseList; + 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()); } - return BoardCreateAndGetResponseList; + BoardCreateAndGetResponseList.add(BoardCreateAndGetResponse.from(board , imageNameList , serverFileUrl,false)); } + return BoardCreateAndGetResponseList; } + @Override public int getBoardCount() { return boardRepository.countAllByBoardNum(); @@ -124,4 +126,6 @@ public int getBoardCount() { public List TitleList(BoardPagination pagination) { return paginationRepository.findTitle(pagination); } + + } diff --git a/src/main/java/com/dailylife/domain/heart/controller/HeartController.java b/src/main/java/com/dailylife/domain/heart/controller/HeartController.java index 56e99f2..8e3fb8d 100644 --- a/src/main/java/com/dailylife/domain/heart/controller/HeartController.java +++ b/src/main/java/com/dailylife/domain/heart/controller/HeartController.java @@ -22,21 +22,18 @@ public class HeartController { @ApiOperation(value = "댓글 좋아요", notes = "replyNum값(tbl_reply)PK값만 넘겨주시면 됩니다. 한 번 누르면 좋아요 / 2번 클릭 시 좋아요 취소") @PostMapping("/replyHeartPlus") public ResponseEntity replyHeartPlus(@Valid @RequestBody HeartStateRequest heartStateRequest){ - System.out.println("댓글 좋아요"); return ResponseEntity.ok(heartService.heartPlusReply(heartStateRequest)); } @ApiOperation(value="게시글 좋아요", notes = "boardNum값(tbl_board)PK값 넘겨주시면 됩니다. 한 번 누르면 좋아요 / 2번 클릭 시 좋아요 취소") @PostMapping("/boardHeartPlus") public ResponseEntity boardHeartPlus(@Valid @RequestBody HeartStateRequest heartStateRequest){ - System.out.println("게시글 좋아요"); return ResponseEntity.ok(heartService.heartPlusBoard(heartStateRequest)); } @ApiOperation(value="대댓글 좋아요", notes = "replyReplyNum(tbl_replyReply)(대댓글)PK값 넘겨주시면 됩니다. 한 번 누르면 좋아요 / 2번 클릭 시 좋아요 취소") @PostMapping("/replyReplyHeartPlus") public ResponseEntity replyReplyHeartPlus(@Valid @RequestBody HeartStateRequest heartStateRequest){ - System.out.println("대댓글 좋아요"); return ResponseEntity.ok(heartService.heartPlusReplyReply(heartStateRequest)); } diff --git a/src/main/java/com/dailylife/domain/heart/service/HeartServiceImpl.java b/src/main/java/com/dailylife/domain/heart/service/HeartServiceImpl.java index 1a76611..9d7ffd3 100644 --- a/src/main/java/com/dailylife/domain/heart/service/HeartServiceImpl.java +++ b/src/main/java/com/dailylife/domain/heart/service/HeartServiceImpl.java @@ -34,11 +34,12 @@ public boolean heartPlusReply(HeartStateRequest heartStateRequest) { if(heartRepository.countByReplyReplyNumAndUserNum(reply.getReplyNum(), user.getUserNum()) == 0){ heartStateRequest.setHeartState(1L); Heart heart = heartRepository.save(Heart.toEntityReply(heartStateRequest, reply)); + return true; } else { heartRepository.deleteByReplyReplyNumAndUserNum(reply.getReplyNum(), user.getUserNum()); + return false; } - return true; } /*게시글 좋아요*/ @@ -52,10 +53,11 @@ public boolean heartPlusBoard(HeartStateRequest heartStateRequest) { if(heartRepository.countByBoardBoardNumAndUserNum(board.getBoardNum(),user.getUserNum())==0){ heartStateRequest.setHeartState(1L); Heart heart = heartRepository.save(Heart.toEntityBoard(heartStateRequest,board)); + return true; }else { heartRepository.deleteByBoardBoardNumAndUserNum(board.getBoardNum(), user.getUserNum()); + return false; } - return true; } /*대댓글 좋아요*/ @@ -69,10 +71,12 @@ public boolean heartPlusReplyReply(HeartStateRequest heartStateRequest) { if(heartRepository.countByCommentReplyReplyNumAndUserNum(comment.getReplyReplyNum(),user.getUserNum())==0){ heartStateRequest.setHeartState(1L); Heart heart = heartRepository.save(Heart.toEntityReplyReply(heartStateRequest, comment)); + return true; }else{ heartRepository.deleteByCommentReplyReplyNumAndUserNum(comment.getReplyReplyNum(),user.getUserNum()); + return false; } - return true; + } /*댓글 좋아요 총 개수 출력*/ diff --git a/src/main/java/com/dailylife/domain/image/service/FileServiceImpl.java b/src/main/java/com/dailylife/domain/image/service/FileServiceImpl.java index 93012a5..0325101 100644 --- a/src/main/java/com/dailylife/domain/image/service/FileServiceImpl.java +++ b/src/main/java/com/dailylife/domain/image/service/FileServiceImpl.java @@ -31,7 +31,6 @@ public class FileServiceImpl implements FileService { @Override public String saveImg(MultipartFile[] imgName) throws IOException{ List images = multiUpload.FileUpload(imgName); - System.out.println(images); return null; } diff --git a/src/main/java/com/dailylife/global/init/InitDB.java b/src/main/java/com/dailylife/global/init/InitDB.java index 8e32f82..b040fd1 100644 --- a/src/main/java/com/dailylife/global/init/InitDB.java +++ b/src/main/java/com/dailylife/global/init/InitDB.java @@ -1,5 +1,7 @@ package com.dailylife.global.init; +import com.dailylife.domain.board.dto.BoardCreateRequest; +import com.dailylife.domain.board.service.BoardService; import com.dailylife.domain.user.dto.UserJoinRequest; import com.dailylife.domain.user.entity.User; import com.dailylife.domain.user.repository.UserRepository; @@ -23,6 +25,8 @@ public class InitDB { private final UserService userService; + private final BoardService boardService; + @PostConstruct public void initDB() throws IOException { if(ddlAutoConfig.equals("create")){ @@ -45,6 +49,7 @@ public void initDB() throws IOException { .userName("dailyLife3") .userEmail("dailyLife.dev@gmail.com").userJoinDate(LocalDateTime.now()).build(); + userService.join(userReq1); userService.join(userReq2); userService.join(userReq3); diff --git a/src/main/java/com/dailylife/global/jwt/service/JwtServiceImpl.java b/src/main/java/com/dailylife/global/jwt/service/JwtServiceImpl.java index 916d9cb..2ff5fa1 100644 --- a/src/main/java/com/dailylife/global/jwt/service/JwtServiceImpl.java +++ b/src/main/java/com/dailylife/global/jwt/service/JwtServiceImpl.java @@ -43,7 +43,6 @@ public String resolveAccessToken() { @Override public String getLoginId() { String accessToken = resolveAccessToken(); - log.info("accessToken = {}" , accessToken); if (accessToken == null || accessToken.length() == 0) throw new RuntimeException("토큰x"); diff --git a/src/main/java/com/dailylife/global/web/WebConfig.java b/src/main/java/com/dailylife/global/web/WebConfig.java index c2c87c1..8ff1768 100644 --- a/src/main/java/com/dailylife/global/web/WebConfig.java +++ b/src/main/java/com/dailylife/global/web/WebConfig.java @@ -53,7 +53,7 @@ public void addInterceptors(InterceptorRegistry registry) { "/api/board/getBoardCount", "/api/heart/countHeartReply/**", "/api/heart/countHeartBoard/**" - ,"/api/board/getBoard"); + ,"/api/board/getBoardNotLogin"); }