Skip to content

Commit

Permalink
Merge pull request #27 from AlongTheBlue/develop
Browse files Browse the repository at this point in the history
Merge to Main from Develop
  • Loading branch information
MoonInbae authored Oct 1, 2024
2 parents 1e721db + 19e831d commit ce7e60d
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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 All @@ -23,6 +24,7 @@
import java.io.IOException;
import java.net.URI;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class RestaurantService {
Expand Down Expand Up @@ -216,10 +218,26 @@ private Mono<Map<String, String>> restdayAndInfo(Restaurant restaurant) {
// //딱 음식 눌렀을 때 식당 목록
public ApiResponse<Page<RestaurantSimpleInformation>> retrieveAll(int page, int size) {
Pageable pageable = PageRequest.of(page, size);
Page<RestaurantSimpleInformation> restaurantPage = restaurantRepository.findAllSimple(pageable);
// TODO 이미지 그룹화 필요
return ApiResponse.ok("음식점 목록을 성공적으로 조회했습니다.", restaurantPage);
//introduction, restDate, infoCenter 없이 반환을 하고 싶음.

// 1. Restaurant 기준으로 페이징 처리된 데이터를 조회
Page<Restaurant> restaurantPage = restaurantRepository.findAll(pageable);

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

// 3. Restaurant 기준으로 페이징을 다시 적용하여 반환
Page<RestaurantSimpleInformation> pagedResult = new PageImpl<>(
groupedRestaurantList, pageable, restaurantPage.getTotalElements());

// 4. 결과를 ApiResponse로 반환
return ApiResponse.ok("음식점 목록을 성공적으로 조회했습니다.", pagedResult);
}
// public List<RestaurantResponseDto> getAll() {
// List<Restaurant> restaurants = restaurantRepository.findAll();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.alongtheblue.alongtheblue_server.global.data.restaurant;

import java.util.List;

public class RestaurantSimpleInformationImpl implements RestaurantSimpleInformation {

private String contentId;
private String title;
private String address;
private List<RestaurantImage> images;

public RestaurantSimpleInformationImpl(String contentId, String title, String address, List<RestaurantImage> images) {
this.contentId = contentId;
this.title = title;
this.address = address;
this.images = images;
}

@Override
public String getContentId() {
return contentId;
}

@Override
public String getTitle() {
return title;
}

@Override
public String getAddress() {
return address;
}

@Override
public List<RestaurantImage> getImages() {
return images;
}

public void addImages(List<RestaurantImage> newImages) {
this.images.addAll(newImages); // 기존 이미지 리스트에 새로운 이미지 추가
}
}

0 comments on commit ce7e60d

Please sign in to comment.