Skip to content

Commit

Permalink
[Feat] TourData detail/all pagination 구현
Browse files Browse the repository at this point in the history
[Feat] TourData detail/all pagination 구현
  • Loading branch information
MoonInbae authored Oct 13, 2024
2 parents 038c30f + e82eb15 commit 69a83bc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -37,6 +36,13 @@ public void getTourDataImages(){
tourDataService.updateAllTourDataImageUrls();
}


@GetMapping("/detail/all")
public ApiResponse<Page<SimpleInformation>> retrieveAll(@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "10") int size) {
return tourDataService.retrieveAll(page, size);
}

@GetMapping("/home")
public ApiResponse<List<TourDataDto>> getHomeTourData() {
return tourDataService.getHomeTourData();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -14,6 +17,9 @@ public interface TourDataRepository extends JpaRepository<TourData, Long> {

// TourData findByContentId(String contentId);

@Query("SELECT t FROM TourData t JOIN t.images i GROUP BY t HAVING COUNT(i) > 0")
Page<SimpleInformation> findAllSimple(Pageable pageable);

@Query(value = "SELECT a.* " +
"FROM tour_data a " +
"JOIN tour_data_image ai ON a.contentsid = ai.tour_data " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -649,5 +652,21 @@ public ApiResponse<List<String>> getHashtagsById(String id) {
// }
// return ApiResponse.ok("음식점 정보를 성공적으로 조회했습니다.", partCafeResponseDtoList);
// }



public ApiResponse<Page<SimpleInformation>> retrieveAll(int page, int size) {
Pageable pageable = PageRequest.of(page, size);

// 1. Cafe 기준으로 페이징 처리된 데이터를 조회
Page<SimpleInformation> cafePage = tourDataRepository.findAllSimple(pageable);

// CustomPage 객체로 변환 (기존 페이지네이션 정보와 category를 함께 담음)
CustomPage<SimpleInformation> customPage = new CustomPage<>(
cafePage.getContent(), pageable, cafePage.getTotalElements(), Category.CAFE.getValue());

// ApiResponse로 반환
return ApiResponse.ok("카페 목록을 성공적으로 조회했습니다.", customPage);
}
}

0 comments on commit 69a83bc

Please sign in to comment.