Skip to content

Commit

Permalink
[Refactor] 커스텀 타입 인터페이스 일반화 작업
Browse files Browse the repository at this point in the history
[Refactor] 커스텀 타입 인터페이스 일반화 작업
  • Loading branch information
MoonInbae authored Oct 13, 2024
2 parents 5fd4222 + 943860e commit cc3d6a4
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.alongtheblue.alongtheblue_server.global.data.global;

import org.alongtheblue.alongtheblue_server.global.data.restaurant.RestaurantImage;

import java.util.List;

public interface SimpleInformation<T> {
String getContentId();
String getTitle();
String getAddress();
List<T> getImages();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import lombok.RequiredArgsConstructor;
import org.alongtheblue.alongtheblue_server.global.common.response.ApiResponse;
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.dto.response.PartRestaurantResponseDto;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
Expand Down Expand Up @@ -45,8 +45,8 @@ public void saveRestaurantsImages() {

// TODO 페이지네이션 구현 필요
@GetMapping("/detail/all")
public ApiResponse<CustomPage<RestaurantSimpleInformation>> retrieveAll(@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "10") int size) {
public ApiResponse<CustomPage<SimpleInformation>> retrieveAll(@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "10") int size) {
return restaurantService.retrieveAll(page, size);
}
// public ApiResponse<List<RestaurantResponseDto>> getAll(){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.alongtheblue.alongtheblue_server.global.data.restaurant;

import org.alongtheblue.alongtheblue_server.global.data.global.SimpleInformation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -10,7 +11,7 @@

public interface RestaurantRepository extends JpaRepository<Restaurant, Long> {
@Query("SELECT r FROM Restaurant r JOIN r.images i GROUP BY r HAVING COUNT(i) > 0")
Page<RestaurantSimpleInformation> findAllSimple(Pageable pageable);
Page<SimpleInformation> findAllSimple(Pageable pageable);

List<Restaurant> findByTitleContaining(String title);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.alongtheblue.alongtheblue_server.global.common.response.ApiResponse;
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.dto.response.PartRestaurantResponseDto;
Expand All @@ -16,7 +17,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 @@ -222,14 +222,14 @@ private Mono<Map<String, String>> restdayAndInfo(Restaurant restaurant) {
}

// //딱 음식 눌렀을 때 식당 목록
public ApiResponse<CustomPage<RestaurantSimpleInformation>> retrieveAll(int page, int size) {
public ApiResponse<CustomPage<SimpleInformation>> retrieveAll(int page, int size) {
Pageable pageable = PageRequest.of(page, size);

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

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

// 로깅 추가: CustomPage의 상태 확인
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package org.alongtheblue.alongtheblue_server.global.data.restaurant;

import org.alongtheblue.alongtheblue_server.global.data.global.SimpleInformation;

import java.util.List;

public class RestaurantSimpleInformationImpl implements RestaurantSimpleInformation {
public class SimpleInformationImpl implements SimpleInformation {

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

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

0 comments on commit cc3d6a4

Please sign in to comment.