From 4c3719931a5fc8c32ab54cb9355f307c0186aa68 Mon Sep 17 00:00:00 2001 From: xhaktmchl Date: Mon, 28 Nov 2022 01:52:54 +0900 Subject: [PATCH] =?UTF-8?q?#9=20#70=20feat:=20=EB=AA=A8=EB=93=A0=20?= =?UTF-8?q?=EC=B9=B4=ED=85=8C=EC=BD=94=EB=A6=AC=20=EB=B3=84=20=EB=B3=B4?= =?UTF-8?q?=EB=93=9C=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C(fi?= =?UTF-8?q?ndBoardsByCategories)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../board/controller/BoardController.java | 16 +++++++++ .../dto/request/GetBoardsByCategories.java | 19 ++++++++++ .../server/board/service/BoardService.java | 2 ++ .../board/service/BoardServiceImpl.java | 36 ++++++++++++++++++- 4 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 server/src/main/java/com/yogit/server/board/dto/request/GetBoardsByCategories.java diff --git a/server/src/main/java/com/yogit/server/board/controller/BoardController.java b/server/src/main/java/com/yogit/server/board/controller/BoardController.java index c6317ca..b73b499 100644 --- a/server/src/main/java/com/yogit/server/board/controller/BoardController.java +++ b/server/src/main/java/com/yogit/server/board/controller/BoardController.java @@ -141,6 +141,22 @@ public ApplicationResponse> findAllBoardsByCategory(@Reques } + /** + * 게시글 모든 카테코리 별 리스트 모음 조회 + * @author 토마스 + */ + @ApiOperation(value = "게시글 모든 카테코리 별 리스트 모음 조회", notes = "그룹 게시글 모든 카테코리 별 리스트 모음 조회") + @ApiResponses({ + @ApiResponse(code= 201, message = "요청에 성공하였습니다."), + @ApiResponse(code= 404, message = "존재하지 않는 유저입니다."), + @ApiResponse(code = 4000 , message = "서버 오류입니다.") + }) + @PostMapping("/get/categories") + public ApplicationResponse>> findBoardsByCategories(@RequestBody @Validated GetBoardsByCategories dto){ + return boardService.findBoardsByCategories(dto); + } + + /** * 게시글 상세 조회 * @author 토마스 diff --git a/server/src/main/java/com/yogit/server/board/dto/request/GetBoardsByCategories.java b/server/src/main/java/com/yogit/server/board/dto/request/GetBoardsByCategories.java new file mode 100644 index 0000000..e6ac594 --- /dev/null +++ b/server/src/main/java/com/yogit/server/board/dto/request/GetBoardsByCategories.java @@ -0,0 +1,19 @@ +package com.yogit.server.board.dto.request; + +import io.swagger.annotations.ApiModelProperty; +import io.swagger.annotations.ApiParam; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +public class GetBoardsByCategories { + + @ApiModelProperty(example = "1") + @ApiParam(value = "유저 ID", required = true) + private Long userId; + + @ApiModelProperty(example = "1") + @ApiParam(value = "페이징 조회 페이지", required = true) + private int cursor; +} diff --git a/server/src/main/java/com/yogit/server/board/service/BoardService.java b/server/src/main/java/com/yogit/server/board/service/BoardService.java index 3662bb4..92b0df0 100644 --- a/server/src/main/java/com/yogit/server/board/service/BoardService.java +++ b/server/src/main/java/com/yogit/server/board/service/BoardService.java @@ -21,6 +21,8 @@ public interface BoardService { ApplicationResponse> findAllBoardsByCategory(GetAllBoardsByCategoryReq getAllBoardsByCategoryReq); + ApplicationResponse>> findBoardsByCategories(GetBoardsByCategories getBoardsByCategories); + ApplicationResponse findBoard(GetBoardReq getBoardReq); ApplicationResponse deleteBoardImage(DeleteBoardImageReq deleteBoardImageReq); diff --git a/server/src/main/java/com/yogit/server/board/service/BoardServiceImpl.java b/server/src/main/java/com/yogit/server/board/service/BoardServiceImpl.java index aaa8c33..e691412 100644 --- a/server/src/main/java/com/yogit/server/board/service/BoardServiceImpl.java +++ b/server/src/main/java/com/yogit/server/board/service/BoardServiceImpl.java @@ -200,11 +200,45 @@ public ApplicationResponse> findAllBoardsByCategory(GetAllB Slice boards = boardRepository.findAllBoardsByCategory(pageRequest, dto.getCategoryId()); // 보드 res에 이미지uuid -> aws s3 url로 변환 List boardsRes = boards.stream() - .map(board -> GetAllBoardRes.toDto(board, awsS3Service.makeUrlOfFilename(awsS3Service.makeUrlOfFilename(board.getBoardImagesUUids().get(0))), awsS3Service.makeUrlOfFilename(user.getProfileImg()))) + .map(board -> GetAllBoardRes.toDto(board, awsS3Service.makeUrlOfFilename(board.getBoardImagesUUids().get(0)), awsS3Service.makeUrlOfFilename(user.getProfileImg()))) .collect(Collectors.toList()); return ApplicationResponse.ok(boardsRes); } + @Transactional(readOnly = true) + @Override + public ApplicationResponse>> findBoardsByCategories(GetBoardsByCategories dto) { + int cursor = dto.getCursor(); + List> boardsByCategories = new ArrayList<>(); + + User user = userRepository.findById(dto.getUserId()) + .orElseThrow(() -> new NotFoundUserException()); + + List categories = categoryRepository.findAllCategories(); + if(categories.isEmpty()){ + System.out.println("카테고리가 없습니다."); + } + + // jpa 다중 정렬 order + Sort sort = Sort.by( + Sort.Order.desc("currentMember"), + Sort.Order.asc("date") + ); + PageRequest pageRequest = PageRequest.of(cursor, PAGING_SIZE, sort); + + // 카테고리 별 리스트 반복문 조회 + for(Category category: categories){ + Slice boards = boardRepository.findAllBoardsByCategory(pageRequest, category.getId()); + // 보드 res에 이미지uuid -> aws s3 url로 변환 + List boardsRes = boards.stream() + .map(board -> GetAllBoardRes.toDto(board, awsS3Service.makeUrlOfFilename(board.getBoardImagesUUids().get(0)), awsS3Service.makeUrlOfFilename(user.getProfileImg()))) + .collect(Collectors.toList()); + + boardsByCategories.add(boardsRes); + } + + return ApplicationResponse.ok(boardsByCategories); + } @Transactional(readOnly = true) @Override