From e82eb15c0ce0e293381e89788951ed93cd7c149e Mon Sep 17 00:00:00 2001 From: MoonInbae <81071736+MoonInbae@users.noreply.github.com> Date: Mon, 14 Oct 2024 04:18:42 +0900 Subject: [PATCH] =?UTF-8?q?[Feat]=20TourData=20detail/all=20pagination=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/tourData/TourDataController.java | 14 ++++++++++---- .../data/tourData/TourDataRepository.java | 6 ++++++ .../global/data/tourData/TourDataService.java | 19 +++++++++++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/alongtheblue/alongtheblue_server/global/data/tourData/TourDataController.java b/src/main/java/org/alongtheblue/alongtheblue_server/global/data/tourData/TourDataController.java index 1337447..abad5a9 100644 --- a/src/main/java/org/alongtheblue/alongtheblue_server/global/data/tourData/TourDataController.java +++ b/src/main/java/org/alongtheblue/alongtheblue_server/global/data/tourData/TourDataController.java @@ -1,13 +1,12 @@ package org.alongtheblue.alongtheblue_server.global.data.tourData; import org.alongtheblue.alongtheblue_server.global.common.response.ApiResponse; +import org.alongtheblue.alongtheblue_server.global.data.global.SimpleInformation; import org.alongtheblue.alongtheblue_server.global.data.global.dto.response.DetailResponseDto; import org.alongtheblue.alongtheblue_server.global.data.global.dto.response.HomeResponseDto; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.data.domain.Page; +import org.springframework.web.bind.annotation.*; import java.util.ArrayList; import java.util.List; @@ -37,6 +36,13 @@ public void getTourDataImages(){ tourDataService.updateAllTourDataImageUrls(); } + + @GetMapping("/detail/all") + public ApiResponse> retrieveAll(@RequestParam(defaultValue = "0") int page, + @RequestParam(defaultValue = "10") int size) { + return tourDataService.retrieveAll(page, size); + } + @GetMapping("/home") public ApiResponse> getHomeTourData() { return tourDataService.getHomeTourData(); diff --git a/src/main/java/org/alongtheblue/alongtheblue_server/global/data/tourData/TourDataRepository.java b/src/main/java/org/alongtheblue/alongtheblue_server/global/data/tourData/TourDataRepository.java index bc3990b..72a8588 100644 --- a/src/main/java/org/alongtheblue/alongtheblue_server/global/data/tourData/TourDataRepository.java +++ b/src/main/java/org/alongtheblue/alongtheblue_server/global/data/tourData/TourDataRepository.java @@ -1,7 +1,10 @@ package org.alongtheblue.alongtheblue_server.global.data.tourData; import org.alongtheblue.alongtheblue_server.global.data.accommodation.Accommodation; +import org.alongtheblue.alongtheblue_server.global.data.global.SimpleInformation; import org.alongtheblue.alongtheblue_server.global.data.tourcommunity.UserTourCourse; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; @@ -14,6 +17,9 @@ public interface TourDataRepository extends JpaRepository { // TourData findByContentId(String contentId); + @Query("SELECT t FROM TourData t JOIN t.images i GROUP BY t HAVING COUNT(i) > 0") + Page findAllSimple(Pageable pageable); + @Query(value = "SELECT a.* " + "FROM tour_data a " + "JOIN tour_data_image ai ON a.contentsid = ai.tour_data " + diff --git a/src/main/java/org/alongtheblue/alongtheblue_server/global/data/tourData/TourDataService.java b/src/main/java/org/alongtheblue/alongtheblue_server/global/data/tourData/TourDataService.java index 7c01e5f..ea4ce68 100644 --- a/src/main/java/org/alongtheblue/alongtheblue_server/global/data/tourData/TourDataService.java +++ b/src/main/java/org/alongtheblue/alongtheblue_server/global/data/tourData/TourDataService.java @@ -10,6 +10,9 @@ import org.alongtheblue.alongtheblue_server.global.data.cafe.Cafe; import org.alongtheblue.alongtheblue_server.global.data.cafe.CafeService; import org.alongtheblue.alongtheblue_server.global.data.cafe.dto.PartCafeResponseDto; +import org.alongtheblue.alongtheblue_server.global.data.global.Category; +import org.alongtheblue.alongtheblue_server.global.data.global.CustomPage; +import org.alongtheblue.alongtheblue_server.global.data.global.SimpleInformation; import org.alongtheblue.alongtheblue_server.global.data.global.dto.response.DetailResponseDto; import org.alongtheblue.alongtheblue_server.global.data.global.dto.response.HomeResponseDto; import org.alongtheblue.alongtheblue_server.global.data.restaurant.Restaurant; @@ -649,5 +652,21 @@ public ApiResponse> getHashtagsById(String id) { // } // return ApiResponse.ok("음식점 정보를 성공적으로 조회했습니다.", partCafeResponseDtoList); // } + + + + public ApiResponse> retrieveAll(int page, int size) { + Pageable pageable = PageRequest.of(page, size); + + // 1. Cafe 기준으로 페이징 처리된 데이터를 조회 + Page cafePage = tourDataRepository.findAllSimple(pageable); + + // CustomPage 객체로 변환 (기존 페이지네이션 정보와 category를 함께 담음) + CustomPage customPage = new CustomPage<>( + cafePage.getContent(), pageable, cafePage.getTotalElements(), Category.CAFE.getValue()); + + // ApiResponse로 반환 + return ApiResponse.ok("카페 목록을 성공적으로 조회했습니다.", customPage); + } }