Skip to content

Commit

Permalink
Merge pull request #37 from AlongTheBlue/develop
Browse files Browse the repository at this point in the history
[Feat] Restaurant pagination 구현
  • Loading branch information
MoonInbae authored Oct 13, 2024
2 parents 1393d99 + 828d287 commit 70e4e5e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class RestaurantImage {

private String originimgurl;

@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "restaurant")
@JsonBackReference
private Restaurant restaurant;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.Optional;

public interface RestaurantRepository extends JpaRepository<Restaurant, Long> {
@Query("SELECT r.contentId AS contentId, r.title AS title, r.addr AS address, r.images AS images FROM Restaurant r")
@Query("SELECT r FROM Restaurant r")
Page<RestaurantSimpleInformation> findAllSimple(Pageable pageable);

List<Restaurant> findByTitleContaining(String title);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.alongtheblue.alongtheblue_server.global.common.response.ApiResponse;
import org.alongtheblue.alongtheblue_server.global.data.accommodation.Accommodation;
import org.alongtheblue.alongtheblue_server.global.data.cafe.Cafe;
import org.alongtheblue.alongtheblue_server.global.data.cafe.CafeRepository;
import org.alongtheblue.alongtheblue_server.global.data.cafe.dto.PartCafeResponseDto;
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.dto.response.PartRestaurantResponseDto;
Expand All @@ -18,7 +14,6 @@
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -231,21 +226,21 @@ public ApiResponse<Page<RestaurantSimpleInformation>> retrieveAll(int page, int
Page<RestaurantSimpleInformation> restaurantPage = restaurantRepository.findAllSimple(pageable);

// 2. RestaurantSimpleInformation으로 변환하여 이미지 그룹화
List<RestaurantSimpleInformation> groupedRestaurantList = restaurantPage.getContent().stream()
.map(restaurant -> new RestaurantSimpleInformationImpl(
restaurant.getContentId(),
restaurant.getTitle(),
restaurant.getAddress(),
restaurant.getImages() // 이미지를 그룹화하지 않고 그대로 넣음
))
.collect(Collectors.toList());

// 3. Restaurant 기준으로 페이징을 다시 적용하여 반환
Page<RestaurantSimpleInformation> pagedResult = new PageImpl<>(
groupedRestaurantList, pageable, restaurantPage.getTotalElements());
// List<RestaurantSimpleInformation> groupedRestaurantList = restaurantPage.getContent().stream()
// .map(restaurant -> new RestaurantSimpleInformationImpl(
// restaurant.getContentId(),
// restaurant.getTitle(),
// restaurant.getAddress(),
// restaurant.getImages() // 이미지를 그룹화하지 않고 그대로 넣음
// ))
// .collect(Collectors.toList());
//
// // 3. Restaurant 기준으로 페이징을 다시 적용하여 반환
// Page<RestaurantSimpleInformation> pagedResult = new PageImpl<>(
// groupedRestaurantList, pageable, restaurantPage.getTotalElements());

// 4. 결과를 ApiResponse로 반환
return ApiResponse.ok("음식점 목록을 성공적으로 조회했습니다.", pagedResult);
return ApiResponse.ok("음식점 목록을 성공적으로 조회했습니다.", restaurantPage);
}
// public List<RestaurantResponseDto> getAll() {
// List<Restaurant> restaurants = restaurantRepository.findAll();
Expand Down

0 comments on commit 70e4e5e

Please sign in to comment.