From 2c2612671e4407ea0d4da0ccdfe8238620021856 Mon Sep 17 00:00:00 2001 From: brinst07 Date: Wed, 5 Mar 2025 21:28:26 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[feat]=20=EC=A0=95=EB=A0=AC=20=EC=A1=B0?= =?UTF-8?q?=EA=B1=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/controller/StoreController.kt | 6 ++- .../controller/dto/request/StoreRequest.kt | 1 + .../store/service/StoreService.kt | 5 ++- .../org/fastcampus/store/entity/Store.kt | 3 ++ .../org/fastcampus/store/enums/OrderType.kt | 11 ++++++ .../store/repository/StoreRepository.kt | 2 + .../store/mongo/document/StoreDocument.kt | 7 ++++ .../repository/StoreMongoRepositoryCustom.kt | 38 +++++++++++++++---- .../src/main/resources/application.yml | 11 +++--- 9 files changed, 68 insertions(+), 16 deletions(-) create mode 100644 domains/store/src/main/kotlin/org/fastcampus/store/enums/OrderType.kt diff --git a/application-client/src/main/kotlin/org/fastcampus/applicationclient/store/controller/StoreController.kt b/application-client/src/main/kotlin/org/fastcampus/applicationclient/store/controller/StoreController.kt index 96d35cae..94df91c4 100644 --- a/application-client/src/main/kotlin/org/fastcampus/applicationclient/store/controller/StoreController.kt +++ b/application-client/src/main/kotlin/org/fastcampus/applicationclient/store/controller/StoreController.kt @@ -10,6 +10,7 @@ import org.fastcampus.common.dto.APIResponseDTO import org.fastcampus.common.dto.CursorDTO import org.fastcampus.common.dto.CursorDTOString import org.fastcampus.store.entity.Store +import org.fastcampus.store.enums.OrderType import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.http.HttpStatus @@ -127,8 +128,8 @@ class StoreController( @RequestParam(defaultValue = "5") size: Int, @RequestParam(required = false) category: Store.Category?, @RequestParam(required = false) keyword: String?, - @RequestParam(required = false) cursor: String?, // "distance_storeId" -// @RequestParam(required = false) order: OrderType?, // "distance_storeId" + @RequestParam(required = false) cursor: String?, + @RequestParam(required = false) orderType: OrderType?, ): ResponseEntity>> { logger.info("category: $category, searchCondition: $keyword") val result = storeService.getStoresByNearByAndConditionCursor( @@ -138,6 +139,7 @@ class StoreController( category = category, keyword = keyword, cursor = cursor, + orderType = orderType, ) return ResponseEntity.ok( APIResponseDTO( diff --git a/application-client/src/main/kotlin/org/fastcampus/applicationclient/store/controller/dto/request/StoreRequest.kt b/application-client/src/main/kotlin/org/fastcampus/applicationclient/store/controller/dto/request/StoreRequest.kt index 8e671e2c..20cb7861 100644 --- a/application-client/src/main/kotlin/org/fastcampus/applicationclient/store/controller/dto/request/StoreRequest.kt +++ b/application-client/src/main/kotlin/org/fastcampus/applicationclient/store/controller/dto/request/StoreRequest.kt @@ -6,4 +6,5 @@ enum class OrderType { DISTANCE, RATING, REVIEW, + ORDER_COUNT, } diff --git a/application-client/src/main/kotlin/org/fastcampus/applicationclient/store/service/StoreService.kt b/application-client/src/main/kotlin/org/fastcampus/applicationclient/store/service/StoreService.kt index b6009de6..2f92c88f 100644 --- a/application-client/src/main/kotlin/org/fastcampus/applicationclient/store/service/StoreService.kt +++ b/application-client/src/main/kotlin/org/fastcampus/applicationclient/store/service/StoreService.kt @@ -17,6 +17,7 @@ import org.fastcampus.common.dto.CursorDTO import org.fastcampus.common.dto.CursorDTOString import org.fastcampus.review.repository.ReviewRepository import org.fastcampus.store.entity.Store +import org.fastcampus.store.enums.OrderType import org.fastcampus.store.exception.StoreException import org.fastcampus.store.redis.Coordinates import org.fastcampus.store.redis.StoreRedisRepository @@ -186,7 +187,8 @@ class StoreService( size: Int, category: Store.Category?, keyword: String?, - cursor: String?, // "distance_storeId" 형태 + cursor: String?, + orderType: OrderType?, ): CursorDTOString? { // 1) cursor 파싱 (ex: "13.23_STORE1234") val (cursorDistance, cursorStoreId) = parseCursor(cursor) @@ -199,6 +201,7 @@ class StoreService( cursorDistance = cursorDistance, cursorStoreId = cursorStoreId, size = size, + orderType = orderType, ) // 3) 결과를 StoreInfo로 변환 diff --git a/domains/store/src/main/kotlin/org/fastcampus/store/entity/Store.kt b/domains/store/src/main/kotlin/org/fastcampus/store/entity/Store.kt index 1fce758d..0ca96973 100644 --- a/domains/store/src/main/kotlin/org/fastcampus/store/entity/Store.kt +++ b/domains/store/src/main/kotlin/org/fastcampus/store/entity/Store.kt @@ -23,6 +23,9 @@ data class Store( val roadAddress: String?, val storeMenuCategory: List?, val minimumOrderAmount: Long, + var orderCount: Int?, + var rating: Float?, + var reviewCount: Int?, ) { fun getCategories(): List { return storeMenuCategory ?: emptyList() diff --git a/domains/store/src/main/kotlin/org/fastcampus/store/enums/OrderType.kt b/domains/store/src/main/kotlin/org/fastcampus/store/enums/OrderType.kt new file mode 100644 index 00000000..04a5bded --- /dev/null +++ b/domains/store/src/main/kotlin/org/fastcampus/store/enums/OrderType.kt @@ -0,0 +1,11 @@ +package org.fastcampus.store.enums + +/** + * Created by brinst07 on 25. 3. 5. + */ +enum class OrderType { + DISTANCE, + RATING, + REVIEW, + ORDER_COUNT, +} diff --git a/domains/store/src/main/kotlin/org/fastcampus/store/repository/StoreRepository.kt b/domains/store/src/main/kotlin/org/fastcampus/store/repository/StoreRepository.kt index 132c611f..e167332b 100644 --- a/domains/store/src/main/kotlin/org/fastcampus/store/repository/StoreRepository.kt +++ b/domains/store/src/main/kotlin/org/fastcampus/store/repository/StoreRepository.kt @@ -2,6 +2,7 @@ package org.fastcampus.store.repository import org.fastcampus.store.entity.Store import org.fastcampus.store.entity.StoreWithDistance +import org.fastcampus.store.enums.OrderType /** * Created by brinst07 on 25. 1. 11.. @@ -35,6 +36,7 @@ interface StoreRepository { cursorDistance: Double?, cursorStoreId: String?, size: Int, + orderType: OrderType?, ): Pair, String?> fun existsStoreNearBy(storeId: String, latitude: Double, longitude: Double, distanceKM: Double): Boolean diff --git a/infrastructure/store-mongo/src/main/kotlin/org/fastcampus/store/mongo/document/StoreDocument.kt b/infrastructure/store-mongo/src/main/kotlin/org/fastcampus/store/mongo/document/StoreDocument.kt index 3f252c87..bdb841bf 100644 --- a/infrastructure/store-mongo/src/main/kotlin/org/fastcampus/store/mongo/document/StoreDocument.kt +++ b/infrastructure/store-mongo/src/main/kotlin/org/fastcampus/store/mongo/document/StoreDocument.kt @@ -37,6 +37,9 @@ class StoreDocument( val minimumOrderAmount: Long, @Transient var distance: Double? = null, // geoNear로 임시 추가되는 필드 + var orderCount: Int?, + var rating: Float?, + var reviewCount: Int?, ) fun StoreDocument.toModel() = @@ -59,4 +62,8 @@ fun StoreDocument.toModel() = roadAddress, storeMenuCategoryDocument?.map { it.toModel() }, minimumOrderAmount, + orderCount ?: 0, + rating ?: 0.0F, + reviewCount ?: 0, ) + diff --git a/infrastructure/store-mongo/src/main/kotlin/org/fastcampus/store/mongo/repository/StoreMongoRepositoryCustom.kt b/infrastructure/store-mongo/src/main/kotlin/org/fastcampus/store/mongo/repository/StoreMongoRepositoryCustom.kt index c4ce1bdd..d6fad407 100644 --- a/infrastructure/store-mongo/src/main/kotlin/org/fastcampus/store/mongo/repository/StoreMongoRepositoryCustom.kt +++ b/infrastructure/store-mongo/src/main/kotlin/org/fastcampus/store/mongo/repository/StoreMongoRepositoryCustom.kt @@ -3,6 +3,7 @@ package org.fastcampus.store.mongo.repository import org.bson.Document import org.fastcampus.store.entity.Store import org.fastcampus.store.entity.StoreWithDistance +import org.fastcampus.store.enums.OrderType import org.fastcampus.store.exception.StoreException import org.fastcampus.store.mongo.document.StoreDocument import org.fastcampus.store.mongo.document.toModel @@ -129,6 +130,7 @@ internal class StoreMongoRepositoryCustom( cursorDistance: Double?, cursorStoreId: String?, size: Int, + orderType: OrderType?, ): Pair, String?> { val pipeline = mutableListOf() @@ -162,14 +164,7 @@ internal class StoreMongoRepositoryCustom( pipeline.add(Aggregation.match(Criteria().orOperator(c1, c2))) } - pipeline.add( - Aggregation.sort( - Sort.by( - Sort.Order.asc("distance"), - Sort.Order.asc("id"), - ), - ), - ) + addOrderCondition(pipeline, orderType) pipeline.add(Aggregation.limit(size.toLong() + 1)) @@ -263,6 +258,33 @@ internal class StoreMongoRepositoryCustom( } return dbCategoryString } + + private fun addOrderCondition(pipeline: MutableList, orderType: OrderType?): List { + // orderType이 null이면 distance로 기본 정렬 + if (orderType == null) { + pipeline.add(Aggregation.sort(Sort.by(Sort.Order.asc("distance")))) + } else { + // orderType에 따라 다른 정렬 추가 + when (orderType) { + OrderType.DISTANCE -> { + pipeline.add(Aggregation.sort(Sort.by(Sort.Order.asc("distance")))) + } + + OrderType.REVIEW -> { + pipeline.add(Aggregation.sort(Sort.by(Sort.Order.desc("reviewCount")))) + } + + OrderType.RATING -> { + pipeline.add(Aggregation.sort(Sort.by(Sort.Order.desc("rating")))) + } + + OrderType.ORDER_COUNT -> { + pipeline.add(Aggregation.sort(Sort.by(Sort.Order.desc("orderCount")))) + } + } + } + return pipeline + } } private fun buildGeoNearOperation( diff --git a/infrastructure/store-mongo/src/main/resources/application.yml b/infrastructure/store-mongo/src/main/resources/application.yml index af316032..05b9e84e 100644 --- a/infrastructure/store-mongo/src/main/resources/application.yml +++ b/infrastructure/store-mongo/src/main/resources/application.yml @@ -1,9 +1,10 @@ spring: data: mongodb: - host: localhost - port: 27017 - database: o2o - username: root - password: root + uri: mongodb://root:root@13.124.27.138:27017/o2o?authSource=admin +# host: localhost +# port: 27017 +# database: o2o +# username: root +# password: root From 594a527b183f4dce60a51c09926e7c4a7da44d7b Mon Sep 17 00:00:00 2001 From: brinst07 Date: Wed, 5 Mar 2025 21:32:03 +0900 Subject: [PATCH 2/2] application.yml rollback --- .../store-mongo/src/main/resources/application.yml | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/infrastructure/store-mongo/src/main/resources/application.yml b/infrastructure/store-mongo/src/main/resources/application.yml index 05b9e84e..2e430608 100644 --- a/infrastructure/store-mongo/src/main/resources/application.yml +++ b/infrastructure/store-mongo/src/main/resources/application.yml @@ -1,10 +1,8 @@ spring: data: mongodb: - uri: mongodb://root:root@13.124.27.138:27017/o2o?authSource=admin -# host: localhost -# port: 27017 -# database: o2o -# username: root -# password: root - + host: localhost + port: 27017 + database: o2o + username: root + password: root