diff --git a/domain/exposure-common-domain/build.gradle b/domain/exposure-common-domain/build.gradle index 9d57c3ac..428bbf38 100644 --- a/domain/exposure-common-domain/build.gradle +++ b/domain/exposure-common-domain/build.gradle @@ -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() -} \ No newline at end of file diff --git a/domain/exposure-common-domain/src/main/java/woowa/team4/bff/domain/RestaurantSummary.java b/domain/exposure-common-domain/src/main/java/woowa/team4/bff/domain/RestaurantSummary.java index 462fc345..aee29606 100644 --- a/domain/exposure-common-domain/src/main/java/woowa/team4/bff/domain/RestaurantSummary.java +++ b/domain/exposure-common-domain/src/main/java/woowa/team4/bff/domain/RestaurantSummary.java @@ -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; + } } diff --git a/domain/exposure-common-domain/src/main/java/woowa/team4/bff/interfaces/SearchService.java b/domain/exposure-common-domain/src/main/java/woowa/team4/bff/interfaces/SearchService.java new file mode 100644 index 00000000..94669189 --- /dev/null +++ b/domain/exposure-common-domain/src/main/java/woowa/team4/bff/interfaces/SearchService.java @@ -0,0 +1,9 @@ +package woowa.team4.bff.interfaces; + +import java.util.List; +import woowa.team4.bff.domain.RestaurantSummary; + +public interface SearchService { + List findIdsByKeywordAndDeliveryLocation(String keyword, String deliveryLocation, Integer pageNumber); + List findRestaurantSummaryByKeywordAndDeliveryLocation(String keyword, String deliveryLocation, Integer pageNumber); +} diff --git a/domain/exposure-domain/build.gradle b/domain/exposure-domain/build.gradle index 428bbf38..cb4384e0 100644 --- a/domain/exposure-domain/build.gradle +++ b/domain/exposure-domain/build.gradle @@ -1,3 +1,5 @@ dependencies { // module + implementation project(":domain:exposure-common-domain") + implementation project(":domain:search-domain-rdb") } diff --git a/domain/exposure-domain/src/main/java/woowa/team4/bff/exposure/command/SearchCommand.java b/domain/exposure-domain/src/main/java/woowa/team4/bff/exposure/command/SearchCommand.java new file mode 100644 index 00000000..a132fcce --- /dev/null +++ b/domain/exposure-domain/src/main/java/woowa/team4/bff/exposure/command/SearchCommand.java @@ -0,0 +1,4 @@ +package woowa.team4.bff.exposure.command; + +public record SearchCommand(String keyword, String deliveryLocation, Integer pageNumber) { +} diff --git a/domain/exposure-domain/src/main/java/woowa/team4/bff/exposure/service/RestaurantExposureListService.java b/domain/exposure-domain/src/main/java/woowa/team4/bff/exposure/service/RestaurantExposureListService.java index bc971e35..9d630c09 100644 --- a/domain/exposure-domain/src/main/java/woowa/team4/bff/exposure/service/RestaurantExposureListService.java +++ b/domain/exposure-domain/src/main/java/woowa/team4/bff/exposure/service/RestaurantExposureListService.java @@ -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 search(SearchCommand command){ +// List restaurantIds = searchService.findIdsByKeywordAndDeliveryLocation(command.keyword(), command.deliveryLocation()); +// return cacheService.findByRestaurantIds(restaurantIds); + return List.of(); + } + + // ToDo: 실험 후 제거 + public List searchNoCache(SearchCommand command){ + return searchService.findRestaurantSummaryByKeywordAndDeliveryLocation(command.keyword(), + command.deliveryLocation(), command.pageNumber()); + } } diff --git a/domain/search-domain-es/build.gradle b/domain/search-domain-es/build.gradle index 2e006d8d..2c9bcb0f 100644 --- a/domain/search-domain-es/build.gradle +++ b/domain/search-domain-es/build.gradle @@ -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") diff --git a/domain/search-domain-es/src/main/java/woowa/team4/bff/search/service/DummyInsertService.java b/domain/search-domain-es/src/main/java/woowa/team4/bff/search/service/BulkInsertService.java similarity index 97% rename from domain/search-domain-es/src/main/java/woowa/team4/bff/search/service/DummyInsertService.java rename to domain/search-domain-es/src/main/java/woowa/team4/bff/search/service/BulkInsertService.java index a0ba760c..59f89b8f 100644 --- a/domain/search-domain-es/src/main/java/woowa/team4/bff/search/service/DummyInsertService.java +++ b/domain/search-domain-es/src/main/java/woowa/team4/bff/search/service/BulkInsertService.java @@ -13,7 +13,7 @@ @Service @RequiredArgsConstructor -public class DummyInsertService { +public class BulkInsertService { private final RestaurantSearchRepository restaurantSearchRepository; private final MenuSearchRepository menuSearchRepository; diff --git a/domain/search-domain-es/src/main/java/woowa/team4/bff/search/service/SearchEsService.java b/domain/search-domain-es/src/main/java/woowa/team4/bff/search/service/SearchEsService.java index a41cf65b..e8c40388 100644 --- a/domain/search-domain-es/src/main/java/woowa/team4/bff/search/service/SearchEsService.java +++ b/domain/search-domain-es/src/main/java/woowa/team4/bff/search/service/SearchEsService.java @@ -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 getRestaurantIdsInEs(String keyword) { - long start = System.currentTimeMillis(); + @Override + public List findIdsByKeywordAndDeliveryLocation(String keyword, String deliveryLocation, Integer pageNumber) { List restaurantSearches = searchEsRepository.findAllByRestaurantName(keyword); List menuSearches = searchEsRepository.findAllByMenuName(keyword); - log.info("Method 'getRestaurantIds' execution time: " + (System.currentTimeMillis() - start)); + List ids = new ArrayList<>(); List 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 findRestaurantSummaryByKeywordAndDeliveryLocation(String keyword, + String deliveryLocation, + Integer pageNumber) { + return List.of(); + } } diff --git a/domain/search-domain-rdb/build.gradle b/domain/search-domain-rdb/build.gradle index 087f6a3e..cccf7cdd 100644 --- a/domain/search-domain-rdb/build.gradle +++ b/domain/search-domain-rdb/build.gradle @@ -1,4 +1,5 @@ dependencies { // module implementation project(":domain:restaurant-domain-rdb") + implementation project(":domain:exposure-common-domain") } diff --git a/domain/search-domain-rdb/src/main/java/woowa/team4/bff/search/command/SearchRestaurantCommand.java b/domain/search-domain-rdb/src/main/java/woowa/team4/bff/search/command/SearchRestaurantCommand.java deleted file mode 100644 index dc1a686a..00000000 --- a/domain/search-domain-rdb/src/main/java/woowa/team4/bff/search/command/SearchRestaurantCommand.java +++ /dev/null @@ -1,7 +0,0 @@ -package woowa.team4.bff.search.command; - -public record SearchRestaurantCommand(String keyword, String deliveryLocation) { - public static SearchRestaurantCommand of(String keyword, String deliveryLocation) { - return new SearchRestaurantCommand(keyword, deliveryLocation); - } -} diff --git a/domain/search-domain-rdb/src/main/java/woowa/team4/bff/search/domain/RestaurantSearchResult.java b/domain/search-domain-rdb/src/main/java/woowa/team4/bff/search/domain/RestaurantSearchResult.java deleted file mode 100644 index 80c66e27..00000000 --- a/domain/search-domain-rdb/src/main/java/woowa/team4/bff/search/domain/RestaurantSearchResult.java +++ /dev/null @@ -1,25 +0,0 @@ -package woowa.team4.bff.search.domain; - -import java.util.UUID; -import lombok.Getter; - -@Getter -public class RestaurantSearchResult { - - private UUID restaurantUuid; - private String restaurantName; - private Integer minimumOrderAmount; - private Double averageRating; - private Long reviewCount; - private String menuNames; - - public RestaurantSearchResult(UUID restaurantUuid, String restaurantName, Integer minimumOrderAmount, - Double averageRating, Long reviewCount, String menuNames) { - this.restaurantUuid = restaurantUuid; - this.restaurantName = restaurantName; - this.minimumOrderAmount = minimumOrderAmount; - this.averageRating = averageRating; - this.reviewCount = reviewCount; - this.menuNames = menuNames; - } -} diff --git a/domain/search-domain-rdb/src/main/java/woowa/team4/bff/search/repository/RestaurantSearchResultRepository.java b/domain/search-domain-rdb/src/main/java/woowa/team4/bff/search/repository/RestaurantSearchResultRepository.java deleted file mode 100644 index adfa074e..00000000 --- a/domain/search-domain-rdb/src/main/java/woowa/team4/bff/search/repository/RestaurantSearchResultRepository.java +++ /dev/null @@ -1,34 +0,0 @@ -package woowa.team4.bff.search.repository; - -import java.util.List; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Repository; -import woowa.team4.bff.search.aop.MethodLogging; -import woowa.team4.bff.search.domain.RestaurantSearchResult; - -@Repository -@RequiredArgsConstructor -public class RestaurantSearchResultRepository { - private final RestaurantSearchResultEntityRepository restaurantSearchResultEntityRepository; - - // - @MethodLogging - public List findByRestaurantIdsAndDeliveryLocation(List restaurantIds, String deliveryLocation){ - return restaurantSearchResultEntityRepository.findByIdsAndDeliveryLocation(restaurantIds, deliveryLocation); - } - - // id in ids - @MethodLogging - public List findByRestaurantIds(List restaurantIds){ - return restaurantSearchResultEntityRepository.findByIds(restaurantIds); - } - - public List findIdsByKeywordAndDeliveryLocation(String keyword, String deliveryLocation){ - return restaurantSearchResultEntityRepository.findIdsByKeywordAndDeliveryLocation(keyword, deliveryLocation); - } - - @MethodLogging - public List findByRestaurantNameAndDeliveryLocation(String keyword, String deliveryLocation) { - return restaurantSearchResultEntityRepository.findByKeywordAndDeliveryLocation(keyword, deliveryLocation); - } -} diff --git a/domain/search-domain-rdb/src/main/java/woowa/team4/bff/search/repository/RestaurantSearchResultEntityRepository.java b/domain/search-domain-rdb/src/main/java/woowa/team4/bff/search/repository/RestaurantSummaryEntityRepository.java similarity index 63% rename from domain/search-domain-rdb/src/main/java/woowa/team4/bff/search/repository/RestaurantSearchResultEntityRepository.java rename to domain/search-domain-rdb/src/main/java/woowa/team4/bff/search/repository/RestaurantSummaryEntityRepository.java index befbd2ee..31a77efa 100644 --- a/domain/search-domain-rdb/src/main/java/woowa/team4/bff/search/repository/RestaurantSearchResultEntityRepository.java +++ b/domain/search-domain-rdb/src/main/java/woowa/team4/bff/search/repository/RestaurantSummaryEntityRepository.java @@ -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 { +public interface RestaurantSummaryEntityRepository extends JpaRepository { // 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 findByIdsAndDeliveryLocation(@Param("restaurantIds") List restaurantIds, + List findByIdsAndDeliveryLocation(@Param("restaurantIds") List 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 findByIds(@Param("restaurantIds") List restaurantIds); - @Query("SELECT DISTINCT r.id " + "FROM RestaurantEntity r " + "LEFT JOIN MenuEntity m ON m.restaurantId = r.id " @@ -40,10 +30,23 @@ List findByIdsAndDeliveryLocation(@Param("restaurantIds" + "LOWER(m.name) LIKE LOWER(CONCAT('%', :keyword, '%'))) " + "GROUP BY r.id, r.uuid, r.name, r.minimumOrderAmount") List 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 findByIds(@Param("restaurantIds") List 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 " @@ -53,6 +56,7 @@ List 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 findByKeywordAndDeliveryLocation(@Param("keyword") String keyword, - @Param("deliveryLocation") String deliveryLocation); + List findByKeywordAndDeliveryLocation(@Param("keyword") String keyword, + @Param("deliveryLocation") String deliveryLocation, + Pageable pageable); } diff --git a/domain/search-domain-rdb/src/main/java/woowa/team4/bff/search/repository/RestaurantSummaryRepository.java b/domain/search-domain-rdb/src/main/java/woowa/team4/bff/search/repository/RestaurantSummaryRepository.java new file mode 100644 index 00000000..1415c2c1 --- /dev/null +++ b/domain/search-domain-rdb/src/main/java/woowa/team4/bff/search/repository/RestaurantSummaryRepository.java @@ -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 findIdsByKeywordAndDeliveryLocation(String keyword, String deliveryLocation, Integer pageNumber){ + return restaurantSummaryEntityRepository.findIdsByKeywordAndDeliveryLocation(keyword, deliveryLocation, PageRequest.of(pageNumber, PAGE_SIZE)); + } + + @MethodLogging + public List findByKeywordAndDeliveryLocation(String keyword, String deliveryLocation, Integer pageNumber) { + return restaurantSummaryEntityRepository.findByKeywordAndDeliveryLocation(keyword, deliveryLocation, PageRequest.of(pageNumber, PAGE_SIZE)); + } + + // id in ids + @MethodLogging + public List findByRestaurantIds(List restaurantIds){ + return restaurantSummaryEntityRepository.findByIds(restaurantIds); + } +} diff --git a/domain/search-domain-rdb/src/main/java/woowa/team4/bff/search/service/SearchRdbService.java b/domain/search-domain-rdb/src/main/java/woowa/team4/bff/search/service/SearchRdbService.java new file mode 100644 index 00000000..9a9ffb92 --- /dev/null +++ b/domain/search-domain-rdb/src/main/java/woowa/team4/bff/search/service/SearchRdbService.java @@ -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 findIdsByKeywordAndDeliveryLocation(String keyword, String deliveryLocation, Integer pageNumber) { + return restaurantSummaryRepository.findIdsByKeywordAndDeliveryLocation(keyword, deliveryLocation, pageNumber); + + } + + @Override + public List findRestaurantSummaryByKeywordAndDeliveryLocation(String keyword, + String deliveryLocation, + Integer pageNumber) { + return restaurantSummaryRepository.findByKeywordAndDeliveryLocation(keyword, deliveryLocation, pageNumber); + } +} diff --git a/dummy-api/build.gradle b/dummy-api/build.gradle new file mode 100644 index 00000000..9ecba92d --- /dev/null +++ b/dummy-api/build.gradle @@ -0,0 +1,41 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '3.3.2' + id 'io.spring.dependency-management' version '1.1.6' +} + +group = 'woowa.team4' +version = '0.0.1-SNAPSHOT' + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(17) + } +} + +configurations { + compileOnly { + extendsFrom annotationProcessor + } +} + +repositories { + mavenCentral() +} + +bootJar.enabled = false +jar.enabled = false + +dependencies { + // web + implementation 'org.springframework.boot:spring-boot-starter-web' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + // module + implementation project(":core-web") + implementation project(":domain:search-domain-rdb") + implementation project(":domain:search-domain-es") +} + +tasks.named('test') { + useJUnitPlatform() +} diff --git a/domain/search-domain-es/src/main/java/woowa/team4/bff/search/dummy/DummyApiController.java b/dummy-api/src/main/java/woowa/team4/bff/dummy/controller/DummyApiController.java similarity index 83% rename from domain/search-domain-es/src/main/java/woowa/team4/bff/search/dummy/DummyApiController.java rename to dummy-api/src/main/java/woowa/team4/bff/dummy/controller/DummyApiController.java index 9ff77e84..ed7d37a1 100644 --- a/domain/search-domain-es/src/main/java/woowa/team4/bff/search/dummy/DummyApiController.java +++ b/dummy-api/src/main/java/woowa/team4/bff/dummy/controller/DummyApiController.java @@ -1,4 +1,5 @@ -package woowa.team4.bff.search.dummy; +package woowa.team4.bff.dummy.controller; + import java.io.BufferedReader; import java.io.IOException; @@ -8,24 +9,24 @@ import java.util.Arrays; import java.util.List; import lombok.RequiredArgsConstructor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import woowa.team4.bff.search.domain.MenuSearch; import woowa.team4.bff.search.domain.RestaurantSearch; -import woowa.team4.bff.search.service.DummyInsertService; - +import woowa.team4.bff.search.service.BulkInsertService; -//@RequestMapping("/api/v1/dummy") -//@RestController +@Slf4j +@RequestMapping("/api/v1/dummy") +@RestController @Component @RequiredArgsConstructor public class DummyApiController { - private final DummyInsertService dummyInsertService; - - private final Logger log = LoggerFactory.getLogger(DummyApiController.class); + private final BulkInsertService bulkInsertRestaurant; - //@PostMapping("/restaurants/{idx}") + @PostMapping("/restaurants/{idx}") public void bulkInsertRestaurant(Integer idx){ String csvFile = "restaurant_es_" + idx + ".csv"; readRestaurant(csvFile); @@ -47,7 +48,7 @@ private void readRestaurant(String filename){ count += 1; if(i == batch_size){ i = 0; - dummyInsertService.bulkInsertRestaurant(restaurantSearchDocuments); + bulkInsertRestaurant.bulkInsertRestaurant(restaurantSearchDocuments); restaurantSearchDocuments = new ArrayList<>(); System.out.println(count + "개 처리"); } @@ -67,7 +68,7 @@ private void readRestaurant(String filename){ .build(); restaurantSearchDocuments.add(restaurantSearchDocument); } - dummyInsertService.bulkInsertRestaurant(restaurantSearchDocuments); + bulkInsertRestaurant.bulkInsertRestaurant(restaurantSearchDocuments); } catch (IOException e) { throw new RuntimeException(e); } @@ -96,7 +97,7 @@ private void readMenu(String filename){ count += 1; if(i == batch_size){ i = 0; - dummyInsertService.bulkInsertMenu(menuSearchDocuments); + bulkInsertRestaurant.bulkInsertMenu(menuSearchDocuments); menuSearchDocuments = new ArrayList<>(); log.info(count + "개 처리"); } @@ -118,7 +119,7 @@ private void readMenu(String filename){ .build(); menuSearchDocuments.add(menuSearchDocument); } - dummyInsertService.bulkInsertMenu(menuSearchDocuments); + bulkInsertRestaurant.bulkInsertMenu(menuSearchDocuments); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/mono/build.gradle b/mono/build.gradle index 4e5b7a0f..ddb2298b 100644 --- a/mono/build.gradle +++ b/mono/build.gradle @@ -39,8 +39,9 @@ dependencies { implementation project(":domain:menu-domain-rdb") implementation project(":domain:restaurant-domain-rdb") implementation project(":domain:review-domain-rdb") - implementation project(":domain:search-domain-rdb") - // implementation project(":domain:search-domain-es") + // + implementation project(":domain:exposure-common-domain") + implementation project(":domain:exposure-domain") } tasks.named('test') { diff --git a/mono/src/main/java/woowa/team4/bff/exposure/controller/RestaurantSummaryApiController.java b/mono/src/main/java/woowa/team4/bff/exposure/controller/RestaurantSummaryApiController.java new file mode 100644 index 00000000..39109be7 --- /dev/null +++ b/mono/src/main/java/woowa/team4/bff/exposure/controller/RestaurantSummaryApiController.java @@ -0,0 +1,42 @@ +package woowa.team4.bff.exposure.controller; + +import static woowa.team4.bff.common.utils.ApiUtils.success; + +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import woowa.team4.bff.common.utils.ApiUtils.ApiResult; +import woowa.team4.bff.domain.RestaurantSummary; +import woowa.team4.bff.exposure.command.SearchCommand; +import woowa.team4.bff.exposure.controller.get.GetRestaurantSummaryRequest; +import woowa.team4.bff.exposure.service.RestaurantExposureListService; + +@RequestMapping("/api/v1/restaurant-summary") +@RestController +@RequiredArgsConstructor +public class RestaurantSummaryApiController { + private final RestaurantExposureListService restaurantExposureListService; + + @GetMapping("/cache") + public ApiResult> getRestaurantSummaries( + @RequestParam("keyword")String keyword, + @RequestParam("deliveryLocation") String deliveryLocation, + @RequestParam("pageNumber") Integer pageNumber + ){ + List response = restaurantExposureListService.search(new SearchCommand(keyword, deliveryLocation, pageNumber)); + return success(response); + } + + @GetMapping("/no-cache") + public ApiResult> getRestaurantSummariesNoCache( + @RequestParam("keyword")String keyword, + @RequestParam("deliveryLocation") String deliveryLocation, + @RequestParam("pageNumber") Integer pageNumber ){ + List response = restaurantExposureListService.searchNoCache(new SearchCommand(keyword, deliveryLocation, pageNumber)); + return success(response); + } +} diff --git a/mono/src/main/java/woowa/team4/bff/exposure/controller/get/GetRestaurantSummaryRequest.java b/mono/src/main/java/woowa/team4/bff/exposure/controller/get/GetRestaurantSummaryRequest.java new file mode 100644 index 00000000..cebf1019 --- /dev/null +++ b/mono/src/main/java/woowa/team4/bff/exposure/controller/get/GetRestaurantSummaryRequest.java @@ -0,0 +1,4 @@ +package woowa.team4.bff.exposure.controller.get; + +public record GetRestaurantSummaryRequest(String keyword, String deliveryLocation, Integer pageNumber) { +} diff --git a/mono/src/main/java/woowa/team4/bff/search/controller/SearchApiController.java b/mono/src/main/java/woowa/team4/bff/search/controller/SearchApiController.java deleted file mode 100644 index ae0c0f61..00000000 --- a/mono/src/main/java/woowa/team4/bff/search/controller/SearchApiController.java +++ /dev/null @@ -1,48 +0,0 @@ -package woowa.team4.bff.search.controller; - -import static woowa.team4.bff.common.utils.ApiUtils.success; - -import java.util.List; -import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; -import woowa.team4.bff.common.utils.ApiUtils.ApiResult; -import woowa.team4.bff.search.domain.RestaurantSearchResult; -import woowa.team4.bff.search.service.SearchService; -import woowa.team4.bff.search.command.SearchRestaurantCommand; - -@RequestMapping("/api/v1/search") -@RestController -@RequiredArgsConstructor -public class SearchApiController { - private final SearchService searchService; - -// @GetMapping("/es") -// public ApiResult> searchRestaurants( -// @RequestParam("keyword") String keyword, -// @RequestParam("deliveryLocation") String deliveryLocation) { -// List response = searchService.searchEs( -// SearchRestaurantCommand.of(keyword, deliveryLocation)); -// return success(response); -// } - - @GetMapping("/like-and-join") - public ApiResult> searchRestaurantsUsingLikeAndJoin( - @RequestParam("keyword") String keyword, - @RequestParam("deliveryLocation") String deliveryLocation) { - List response = searchService.searchLikeAndJoin( - SearchRestaurantCommand.of(keyword, deliveryLocation)); - return success(response); - } - - @GetMapping("/like-after-join") - public ApiResult> searchRestaurantsUsingLikeAfterJoin( - @RequestParam("keyword") String keyword, - @RequestParam("deliveryLocation") String deliveryLocation) { - List response = searchService.searchLikeAfterJoin( - SearchRestaurantCommand.of(keyword, deliveryLocation)); - return success(response); - } -} diff --git a/mono/src/main/java/woowa/team4/bff/search/service/SearchService.java b/mono/src/main/java/woowa/team4/bff/search/service/SearchService.java deleted file mode 100644 index 165276d8..00000000 --- a/mono/src/main/java/woowa/team4/bff/search/service/SearchService.java +++ /dev/null @@ -1,44 +0,0 @@ -package woowa.team4.bff.search.service; - - -import java.util.ArrayList; -import java.util.List; -import lombok.RequiredArgsConstructor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Service; -import woowa.team4.bff.restaurant.repository.RestaurantFinder; -import woowa.team4.bff.search.command.SearchRestaurantCommand; -import woowa.team4.bff.search.domain.RestaurantSearchResult; -import woowa.team4.bff.search.repository.RestaurantSearchResultRepository; - -@Service -@RequiredArgsConstructor -public class SearchService { - //private final SearchEsService searchEsService; - private final RestaurantFinder restaurantFinder; - private final RestaurantSearchResultRepository restaurantSearchResultRepository; - private final Logger log = LoggerFactory.getLogger(SearchService.class); - -// public List searchEs(SearchRestaurantCommand command) { -// return restaurantSearchResultRepository.findByRestaurantIdsAndDeliveryLocation(getRestaurantIdsInEs(command.keyword()), command.deliveryLocation()); -// } -// -// private List getRestaurantIdsInEs(String keyword) { -// searchEsService.getRestaurantIdsInEs(keyword); -// } - - public List searchLikeAndJoin(SearchRestaurantCommand command) { - return restaurantSearchResultRepository.findByRestaurantNameAndDeliveryLocation(command.keyword(), command.deliveryLocation()); - } - - public List searchLikeAfterJoin(SearchRestaurantCommand command) { - long start = System.currentTimeMillis(); - List ret = new ArrayList<>(); - List ids = restaurantSearchResultRepository.findIdsByKeywordAndDeliveryLocation(command.keyword(), command.deliveryLocation()); - log.info("Method 'findIdsByKeywordAndDeliveryLocation' execution time: " + (System.currentTimeMillis() - start)); - log.info("hit-restaurantIds-by-restaurantName "+ ids); - ret.addAll(ids); - return restaurantSearchResultRepository.findByRestaurantIds(ret); - } -} diff --git a/mono/src/main/resources/application.yml b/mono/src/main/resources/application.yml index cad069f7..aa7d23a7 100644 --- a/mono/src/main/resources/application.yml +++ b/mono/src/main/resources/application.yml @@ -19,16 +19,16 @@ spring: hibernate: format_sql: true hibernate: - ddl-auto: update + ddl-auto: none - elasticsearch: - uris: http://localhost:9200 - username: elastic - password: your_elastic_password - data: - elasticsearch: - repositories: - enabled: true +# elasticsearch: +# uris: http://localhost:9200 +# username: elastic +# password: your_elastic_password +# data: +# elasticsearch: +# repositories: +# enabled: true logging: level: diff --git a/settings.gradle b/settings.gradle index ae3e35d5..aa80d2ae 100644 --- a/settings.gradle +++ b/settings.gradle @@ -29,4 +29,5 @@ include 'domain:exposure-domain' findProject(':domain:exposure-domain')?.name = 'exposure-domain' include 'domain:exposure-common-domain' findProject(':domain:exposure-common-domain')?.name = 'exposure-common-domain' +include 'dummy-api'