From dfe0230a9e32952297dd657f7577d2ae2ea2bb11 Mon Sep 17 00:00:00 2001 From: xhaktmchl Date: Sun, 30 Apr 2023 00:00:30 +0900 Subject: [PATCH] =?UTF-8?q?#9=20feat:=20=EB=B3=B4=EB=93=9C=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8CAPI-=EB=8F=84=EC=8B=9C=20=EB=B3=84(1=EA=B0=9C)=20?= =?UTF-8?q?=EC=A0=84=EC=B2=B4=20=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../board/controller/BoardController.java | 16 +++++++ .../dto/request/GetAllBoardsByCityReq.java | 27 ++++++++++++ .../dto/response/GetAllBoardsByCityRes.java | 33 ++++++++++++++ .../board/repository/BoardRepository.java | 3 ++ .../server/board/service/BoardService.java | 2 + .../board/service/BoardServiceImpl.java | 44 +++++++++++++++++++ 6 files changed, 125 insertions(+) create mode 100644 server/src/main/java/com/yogit/server/board/dto/request/GetAllBoardsByCityReq.java create mode 100644 server/src/main/java/com/yogit/server/board/dto/response/GetAllBoardsByCityRes.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 e892260..aa21806 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 @@ -161,6 +161,22 @@ public ApplicationResponse>> findBoardsByCategories(@R return boardService.findBoardsByCategories(dto); } + + /** + * 게시글 도시 별(1개) 전체 조회 + * @author 토마스 + */ + @ApiOperation(value = "게시글 도시 별(1개) 전체 조회", notes = "게시글 도시 별(1개) 전체 조회") + @ApiResponses({ + @ApiResponse(code= 201, message = "요청에 성공하였습니다."), + @ApiResponse(code= 404, message = "존재하지 않는 유저입니다."), + @ApiResponse(code = 4000 , message = "서버 오류입니다.") + }) + @PostMapping("/get/city") + public ApplicationResponse findAllBoardsByCityName(@RequestBody @Validated GetAllBoardsByCityReq getAllBoardsByCityReq){ + return boardService.findAllBoardsByCityName(getAllBoardsByCityReq); + } + /** * 게시글 My Club 조회: 자신이 생성한 보드들 조회 * @author 토마스 diff --git a/server/src/main/java/com/yogit/server/board/dto/request/GetAllBoardsByCityReq.java b/server/src/main/java/com/yogit/server/board/dto/request/GetAllBoardsByCityReq.java new file mode 100644 index 0000000..ad79bb3 --- /dev/null +++ b/server/src/main/java/com/yogit/server/board/dto/request/GetAllBoardsByCityReq.java @@ -0,0 +1,27 @@ +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 GetAllBoardsByCityReq { + + @ApiModelProperty(example = "1") + @ApiParam(value = "유저 ID", required = true) + private Long userId; + + @ApiModelProperty(example = "1") + @ApiParam(value = "페이징 조회 페이지", required = true) + private int cursor; + + @ApiModelProperty(example = "SEOUL") + @ApiParam(value = "City 이름", required = true) + private String cityName; + + @ApiModelProperty(example = "reb5085c395164587b84ac583d023011f.0.sryrq.IDLsECw-rsTozfsX0Yz-CA") + @ApiParam(value = "애플 리프레쉬 토큰", required = true) + private String refreshToken; +} diff --git a/server/src/main/java/com/yogit/server/board/dto/response/GetAllBoardsByCityRes.java b/server/src/main/java/com/yogit/server/board/dto/response/GetAllBoardsByCityRes.java new file mode 100644 index 0000000..6701058 --- /dev/null +++ b/server/src/main/java/com/yogit/server/board/dto/response/GetAllBoardsByCityRes.java @@ -0,0 +1,33 @@ +package com.yogit.server.board.dto.response; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@NoArgsConstructor +public class GetAllBoardsByCityRes { + + @ApiModelProperty(example = "[보드1, 보드2]", value = "보드 리스트") + private List getAllBoardResList; + + @ApiModelProperty(example = "10", value = "페이징 전체 페이지") + private int totalPage; + + @Builder + public GetAllBoardsByCityRes(List getAllBoardResList, int totalPage) { + this.getAllBoardResList = getAllBoardResList; + this.totalPage = totalPage; + } + + + public static GetAllBoardsByCityRes toDto(List getAllBoardResList, int totalPage){ + return GetAllBoardsByCityRes.builder() + .getAllBoardResList(getAllBoardResList) + .totalPage(totalPage) + .build(); + } +} diff --git a/server/src/main/java/com/yogit/server/board/repository/BoardRepository.java b/server/src/main/java/com/yogit/server/board/repository/BoardRepository.java index 7b5ab28..a45ce98 100644 --- a/server/src/main/java/com/yogit/server/board/repository/BoardRepository.java +++ b/server/src/main/java/com/yogit/server/board/repository/BoardRepository.java @@ -24,6 +24,9 @@ public interface BoardRepository extends JpaRepository { @Query("select b from Board b where b.status = 'ACTIVE' and b.category.id = :categoryId") Page findAllBoardsByCategory(Pageable pageable, @Param("categoryId") Long categoryId); + @Query("select b from Board b where b.status = 'ACTIVE' and b.city.cityName = :cityName") + Page findAllBoardsByCityName(Pageable pageable, @Param("cityName") String cityName); + @Query("select b from Board b where b.status = 'ACTIVE' and b.host.id = :userId") Page findMyClubBoardsByUserId(Pageable pageable, @Param("userId") Long userId); 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 75471ef..37fa3d8 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 @@ -27,4 +27,6 @@ public interface BoardService { ApplicationResponse findBoard(GetBoardReq getBoardReq); ApplicationResponse deleteBoardImage(DeleteBoardImageReq deleteBoardImageReq); + + ApplicationResponse findAllBoardsByCityName(GetAllBoardsByCityReq getAllBoardsByCityReq); } 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 dd41efa..a156953 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 @@ -395,6 +395,50 @@ public ApplicationResponse>> findBoardsByCategories(Ge return ApplicationResponse.ok(boardsByCategories); } + + @Transactional(readOnly = true) + @Override + public ApplicationResponse findAllBoardsByCityName(GetAllBoardsByCityReq dto){ + + tokenService.validateRefreshToken(dto.getUserId(), dto.getRefreshToken()); + + int cursor = dto.getCursor(); + + User user = userRepository.findByUserId(dto.getUserId()) + .orElseThrow(() -> new NotFoundUserException()); + + List blockedUsers = blockRepository.findBlocksByBlockingUserId(dto.getUserId()).stream() + .map(block -> block.getBlockedUser()) + .collect(Collectors.toList()); + + // jpa 다중 정렬 order + Sort sort = Sort.by( + Sort.Order.desc("id") + ); + PageRequest pageRequest = PageRequest.of(cursor, PAGING_SIZE, sort); + + Page boards = boardRepository.findAllBoardsByCityName(pageRequest, dto.getCityName()); + // 보드 res에 이미지uuid -> aws s3 url로 변환 + /*List boardsRes = boards.stream() + .filter(board -> !blockedUsers.contains(board.getHost())) // 차단당한 유저의 데이터 제외 + .map(board -> GetAllBoardRes.toDto(board, awsS3Service.makeUrlOfFilename(board.getBoardImagesUUids().get(0)), board.getBoardUsers().stream().map(boardUser -> awsS3Service.makeUrlOfFilename(boardUser.getUser().getProfileImg())).collect(Collectors.toList()))) + .collect(Collectors.toList());*/ + + // 보드 res에 이미지uuid -> aws s3 url로 변환 + //TODO: 동작 잘 되는지 확인 + List boardsRes = new ArrayList<>(); + for(Board b:boards){ + if(!blockedUsers.contains(b.getHost())){ + // 보드 현재 인원 + List participantsOrigin = boardUserRepository.findAllByBoardId(b.getId()); + b.changeBoardCurrentMember(participantsOrigin.size()); + boardsRes.add(GetAllBoardRes.toDto(b, awsS3Service.makeUrlOfFilename(b.getBoardImagesUUids().get(0)), b.getBoardUsers().stream().filter(boardUser -> boardUser.getStatus().equals(BaseStatus.ACTIVE)).map(boardUser -> awsS3Service.makeUrlOfFilename(boardUser.getUser().getProfileImg())).collect(Collectors.toList()))); + } + } + + return ApplicationResponse.ok(GetAllBoardsByCityRes.toDto(boardsRes, boards.getTotalPages())); + } + @Transactional(readOnly = true) @Override public ApplicationResponse findBoard(GetBoardReq dto){