Skip to content

Commit

Permalink
Merge pull request #98 from woowa-techcamp-2024/feature/88-restauarnt…
Browse files Browse the repository at this point in the history
…-exposure

[feature] restauarnt exposure
  • Loading branch information
huiseung authored Aug 20, 2024
2 parents acbd2ca + cafc728 commit 1884a1e
Show file tree
Hide file tree
Showing 25 changed files with 262 additions and 233 deletions.
18 changes: 1 addition & 17 deletions domain/exposure-common-domain/build.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
plugins {
id 'java'
}

group = 'woowa.team4'
version = '0.0.1-SNAPSHOT'

repositories {
mavenCentral()
}

dependencies {
testImplementation platform('org.junit:junit-bom:5.10.0')
testImplementation 'org.junit.jupiter:junit-jupiter'
// module
}

test {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ public class RestaurantSummary {
private UUID restaurantUuid;
private String restaurantName;
private String restaurantThumbnailUrl;
private Integer reviewCount;
private Double rating;
private int minimumOrderAmount;
private long reviewCount;
private double rating;
private String menus;

public void updateReviewStatistics(Double rating, Long reviewCount) {
this.rating = rating;
this.reviewCount = reviewCount;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package woowa.team4.bff.interfaces;

import java.util.List;
import woowa.team4.bff.domain.RestaurantSummary;

public interface SearchService {
List<Long> findIdsByKeywordAndDeliveryLocation(String keyword, String deliveryLocation, Integer pageNumber);
List<RestaurantSummary> findRestaurantSummaryByKeywordAndDeliveryLocation(String keyword, String deliveryLocation, Integer pageNumber);
}
2 changes: 2 additions & 0 deletions domain/exposure-domain/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
dependencies {
// module
implementation project(":domain:exposure-common-domain")
implementation project(":domain:search-domain-rdb")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package woowa.team4.bff.exposure.command;

public record SearchCommand(String keyword, String deliveryLocation, Integer pageNumber) {
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
package woowa.team4.bff.exposure.service;

import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import woowa.team4.bff.domain.RestaurantSummary;
import woowa.team4.bff.exposure.command.SearchCommand;
import woowa.team4.bff.interfaces.CacheService;
import woowa.team4.bff.interfaces.SearchService;

@Slf4j
@Service
@RequiredArgsConstructor
public class RestaurantExposureListService {

private final SearchService searchService;
// private final CacheService cacheService;

public List<RestaurantSummary> search(SearchCommand command){
// List<Long> restaurantIds = searchService.findIdsByKeywordAndDeliveryLocation(command.keyword(), command.deliveryLocation());
// return cacheService.findByRestaurantIds(restaurantIds);
return List.of();
}

// ToDo: 실험 후 제거
public List<RestaurantSummary> searchNoCache(SearchCommand command){
return searchService.findRestaurantSummaryByKeywordAndDeliveryLocation(command.keyword(),
command.deliveryLocation(), command.pageNumber());
}
}
1 change: 1 addition & 0 deletions domain/search-domain-es/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ dependencies {
// db
implementation 'org.springframework.boot:spring-boot-starter-data-elasticsearch:2.7.18'
// module
implementation project(":domain:exposure-common-domain")
implementation project(":event:common-event")
implementation project(":event:restaurant-event")
implementation project(":event:menu-event")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

@Service
@RequiredArgsConstructor
public class DummyInsertService {
public class BulkInsertService {
private final RestaurantSearchRepository restaurantSearchRepository;
private final MenuSearchRepository menuSearchRepository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,37 @@
import java.util.ArrayList;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import woowa.team4.bff.domain.RestaurantSummary;
import woowa.team4.bff.interfaces.SearchService;
import woowa.team4.bff.search.domain.MenuSearch;
import woowa.team4.bff.search.domain.RestaurantSearch;
import woowa.team4.bff.search.repository.SearchEsRepository;

@Slf4j
@Service
@RequiredArgsConstructor
public class SearchEsService {
public class SearchEsService implements SearchService {
private final SearchEsRepository searchEsRepository;
private final Logger log = LoggerFactory.getLogger(SearchEsService.class);

private List<Long> getRestaurantIdsInEs(String keyword) {
long start = System.currentTimeMillis();
@Override
public List<Long> findIdsByKeywordAndDeliveryLocation(String keyword, String deliveryLocation, Integer pageNumber) {
List<RestaurantSearch> restaurantSearches = searchEsRepository.findAllByRestaurantName(keyword);
List<MenuSearch> menuSearches = searchEsRepository.findAllByMenuName(keyword);
log.info("Method 'getRestaurantIds' execution time: " + (System.currentTimeMillis() - start));

List<Long> ids = new ArrayList<>();
List<Long> results = restaurantSearches.stream().map(RestaurantSearch::getRestaurantId).toList();
ids.addAll(results);
log.info("hit-restaurantIds-by-restaurantName "+ ids);
results = menuSearches.stream().map(MenuSearch::getRestaurantId).toList();
log.info("hit-restaurantIds-by-menuName");
ids.addAll(results);
return ids;
}

@Override
public List<RestaurantSummary> findRestaurantSummaryByKeywordAndDeliveryLocation(String keyword,
String deliveryLocation,
Integer pageNumber) {
return List.of();
}
}
1 change: 1 addition & 0 deletions domain/search-domain-rdb/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dependencies {
// module
implementation project(":domain:restaurant-domain-rdb")
implementation project(":domain:exposure-common-domain")
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,36 +1,26 @@
package woowa.team4.bff.search.repository;

import java.util.List;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import woowa.team4.bff.domain.RestaurantSummary;
import woowa.team4.bff.restaurant.entity.RestaurantEntity;
import woowa.team4.bff.search.domain.RestaurantSearchResult;

public interface RestaurantSearchResultEntityRepository extends JpaRepository<RestaurantEntity, Long> {
public interface RestaurantSummaryEntityRepository extends JpaRepository<RestaurantEntity, Long> {
// ToDo: Document 에 배달 가능 위치도 저장하는걸로 바꾸면 해당 메서드 제거
@Query(
"SELECT new woowa.team4.bff.search.domain.RestaurantSearchResult(r.uuid, r.name, r.minimumOrderAmount, COALESCE(rs.averageRating, 0.0), COALESCE(rs.reviewCount, 0), CAST(COALESCE(GROUP_CONCAT(m.name), '') AS string)) "
"SELECT new woowa.team4.bff.domain.RestaurantSummary(r.uuid, r.name, r.image, r.minimumOrderAmount, COALESCE(rs.reviewCount, 0), COALESCE(rs.averageRating, 0.0), CAST(COALESCE(GROUP_CONCAT(m.name), '') AS string)) "
+ "FROM RestaurantEntity r "
+ "LEFT JOIN MenuEntity m ON m.restaurantId = r.id "
+ "LEFT JOIN ReviewStatisticsEntity rs ON rs.restaurantId = r.id "
+ "WHERE r.id IN :restaurantIds AND r.deliveryLocation = :deliveryLocation "
+ "GROUP BY r.id, r.uuid, r.name, r.minimumOrderAmount, rs.averageRating, rs.reviewCount"
)
List<RestaurantSearchResult> findByIdsAndDeliveryLocation(@Param("restaurantIds") List<Long> restaurantIds,
List<RestaurantSummary> findByIdsAndDeliveryLocation(@Param("restaurantIds") List<Long> restaurantIds,
@Param("deliveryLocation") String deliveryLocation);


@Query(
"SELECT new woowa.team4.bff.search.domain.RestaurantSearchResult(r.uuid, r.name, r.minimumOrderAmount, COALESCE(rs.averageRating, 0.0), COALESCE(rs.reviewCount, 0), CAST(COALESCE(GROUP_CONCAT(m.name), '') AS string)) "
+ "FROM RestaurantEntity r "
+ "LEFT JOIN MenuEntity m ON m.restaurantId = r.id "
+ "LEFT JOIN ReviewStatisticsEntity rs ON rs.restaurantId = r.id "
+ "WHERE r.id IN :restaurantIds "
+ "GROUP BY r.id, r.uuid, r.name, r.minimumOrderAmount, rs.averageRating, rs.reviewCount"
)
List<RestaurantSearchResult> findByIds(@Param("restaurantIds") List<Long> restaurantIds);

@Query("SELECT DISTINCT r.id "
+ "FROM RestaurantEntity r "
+ "LEFT JOIN MenuEntity m ON m.restaurantId = r.id "
Expand All @@ -40,10 +30,23 @@ List<RestaurantSearchResult> findByIdsAndDeliveryLocation(@Param("restaurantIds"
+ "LOWER(m.name) LIKE LOWER(CONCAT('%', :keyword, '%'))) "
+ "GROUP BY r.id, r.uuid, r.name, r.minimumOrderAmount")
List<Long> findIdsByKeywordAndDeliveryLocation(@Param("keyword") String keyword,
@Param("deliveryLocation") String deliveryLocation);
@Param("deliveryLocation") String deliveryLocation,
Pageable pageable);


@Query(
"SELECT new woowa.team4.bff.domain.RestaurantSummary(r.uuid, r.name, r.image, r.minimumOrderAmount, COALESCE(rs.reviewCount, 0), COALESCE(rs.averageRating, 0.0), CAST(COALESCE(GROUP_CONCAT(m.name), '') AS string)) "
+ "FROM RestaurantEntity r "
+ "LEFT JOIN MenuEntity m ON m.restaurantId = r.id "
+ "LEFT JOIN ReviewStatisticsEntity rs ON rs.restaurantId = r.id "
+ "WHERE r.id IN :restaurantIds "
+ "GROUP BY r.id, r.uuid, r.name, r.minimumOrderAmount, rs.averageRating, rs.reviewCount"
)
List<RestaurantSummary> findByIds(@Param("restaurantIds") List<Long> restaurantIds);


@Query(
"SELECT new woowa.team4.bff.search.domain.RestaurantSearchResult(r.uuid, r.name, r.minimumOrderAmount, COALESCE(rs.averageRating, 0.0), COALESCE(rs.reviewCount, 0), CAST(COALESCE(GROUP_CONCAT(m.name), '') AS string)) "
"SELECT new woowa.team4.bff.domain.RestaurantSummary(r.uuid, r.name, r.image, r.minimumOrderAmount, COALESCE(rs.reviewCount, 0), COALESCE(rs.averageRating, 0.0), CAST(COALESCE(GROUP_CONCAT(m.name), '') AS string)) "
+ "FROM RestaurantEntity r "
+ "LEFT JOIN MenuEntity m ON m.restaurantId = r.id "
+ "LEFT JOIN ReviewStatisticsEntity rs ON rs.restaurantId = r.id "
Expand All @@ -53,6 +56,7 @@ List<Long> findIdsByKeywordAndDeliveryLocation(@Param("keyword") String keyword,
+ "LOWER(m.name) LIKE LOWER(CONCAT('%', :keyword, '%'))) "
+ "GROUP BY r.id, r.uuid, r.name, r.minimumOrderAmount, rs.averageRating, rs.reviewCount"
)
List<RestaurantSearchResult> findByKeywordAndDeliveryLocation(@Param("keyword") String keyword,
@Param("deliveryLocation") String deliveryLocation);
List<RestaurantSummary> findByKeywordAndDeliveryLocation(@Param("keyword") String keyword,
@Param("deliveryLocation") String deliveryLocation,
Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package woowa.team4.bff.search.repository;

import java.awt.print.Pageable;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Repository;
import woowa.team4.bff.domain.RestaurantSummary;
import woowa.team4.bff.search.aop.MethodLogging;

@Repository
@RequiredArgsConstructor
public class RestaurantSummaryRepository {
private final int PAGE_SIZE = 25;
private final RestaurantSummaryEntityRepository restaurantSummaryEntityRepository;

@MethodLogging
public List<Long> findIdsByKeywordAndDeliveryLocation(String keyword, String deliveryLocation, Integer pageNumber){
return restaurantSummaryEntityRepository.findIdsByKeywordAndDeliveryLocation(keyword, deliveryLocation, PageRequest.of(pageNumber, PAGE_SIZE));
}

@MethodLogging
public List<RestaurantSummary> findByKeywordAndDeliveryLocation(String keyword, String deliveryLocation, Integer pageNumber) {
return restaurantSummaryEntityRepository.findByKeywordAndDeliveryLocation(keyword, deliveryLocation, PageRequest.of(pageNumber, PAGE_SIZE));
}

// id in ids
@MethodLogging
public List<RestaurantSummary> findByRestaurantIds(List<Long> restaurantIds){
return restaurantSummaryEntityRepository.findByIds(restaurantIds);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package woowa.team4.bff.search.service;

import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import woowa.team4.bff.domain.RestaurantSummary;
import woowa.team4.bff.interfaces.SearchService;
import woowa.team4.bff.search.repository.RestaurantSummaryRepository;

@Slf4j
@Service
@RequiredArgsConstructor
public class SearchRdbService implements SearchService {
private final RestaurantSummaryRepository restaurantSummaryRepository;

@Override
public List<Long> findIdsByKeywordAndDeliveryLocation(String keyword, String deliveryLocation, Integer pageNumber) {
return restaurantSummaryRepository.findIdsByKeywordAndDeliveryLocation(keyword, deliveryLocation, pageNumber);

}

@Override
public List<RestaurantSummary> findRestaurantSummaryByKeywordAndDeliveryLocation(String keyword,
String deliveryLocation,
Integer pageNumber) {
return restaurantSummaryRepository.findByKeywordAndDeliveryLocation(keyword, deliveryLocation, pageNumber);
}
}
Loading

0 comments on commit 1884a1e

Please sign in to comment.