diff --git a/gradle.properties b/gradle.properties index b19f983..232fd22 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ ### Application version ### -applicationVersion=0.1.7-RELEASE +applicationVersion=0.1.8-RELEASE ### Project configs ### projectGroup="com.mjucow" diff --git a/src/main/kotlin/com/mjucow/eatda/common/config/SwaggerConfig.kt b/src/main/kotlin/com/mjucow/eatda/common/config/SwaggerConfig.kt index 0d3ec51..ba6856e 100644 --- a/src/main/kotlin/com/mjucow/eatda/common/config/SwaggerConfig.kt +++ b/src/main/kotlin/com/mjucow/eatda/common/config/SwaggerConfig.kt @@ -15,6 +15,6 @@ class SwaggerConfig { Info() .title("Eatda API Documentation") .description("Eatda(잇다) 서비스의 API 명세서입니다.") - .version("0.1.7") + .version("0.1.8") ) } diff --git a/src/main/kotlin/com/mjucow/eatda/domain/store/service/query/StoreQueryService.kt b/src/main/kotlin/com/mjucow/eatda/domain/store/service/query/StoreQueryService.kt index 5b9a7fe..85056cf 100644 --- a/src/main/kotlin/com/mjucow/eatda/domain/store/service/query/StoreQueryService.kt +++ b/src/main/kotlin/com/mjucow/eatda/domain/store/service/query/StoreQueryService.kt @@ -13,12 +13,19 @@ class StoreQueryService( val repository: StoreRepository, val popularStoreCommandService: PopularStoreCommandService, ) { - fun findAllByCategoryAndCursor(id: Long? = null, categoryId: Long? = null, size: Int): List { + fun findAllByCategoryAndCursor(cursor: Long? = null, categoryId: Long? = null, size: Int): List { return if (categoryId == null) { - repository.findAllByIdLessThanOrderByIdDesc(size, id).map(StoreDto::from) + repository.findAllByIdLessThanOrderByIdDesc( + size = size, + id = cursor + ).map(StoreDto::from) } else { // FIXME(cache): store 캐시 처리 이후 store 조회 개선하기 - val storeIds = repository.findIdsByCategoryIdOrderByIdDesc(categoryId, size, id) + val storeIds = repository.findIdsByCategoryIdOrderByIdDesc( + categoryId = categoryId, + size = size, + id = cursor + ) repository.findAllByIdInOrderByIdDesc(storeIds).map(StoreDto::from) } } diff --git a/src/main/kotlin/com/mjucow/eatda/presentation/store/StoreApiPresentation.kt b/src/main/kotlin/com/mjucow/eatda/presentation/store/StoreApiPresentation.kt index f68a80c..dd8b2f9 100644 --- a/src/main/kotlin/com/mjucow/eatda/presentation/store/StoreApiPresentation.kt +++ b/src/main/kotlin/com/mjucow/eatda/presentation/store/StoreApiPresentation.kt @@ -21,7 +21,7 @@ interface StoreApiPresentation { @Operation(summary = "커서 기반 카테고리 가게 조회", description = "커서를 기반으로 가게를 조회합니다.") @StoreDtosApiResponse fun findAllByCategoryIdAndCursor( - storeId: Long?, + cursor: Long?, categoryId: Long?, pageSize: Int, ): ApiResponse> diff --git a/src/main/kotlin/com/mjucow/eatda/presentation/store/StoreController.kt b/src/main/kotlin/com/mjucow/eatda/presentation/store/StoreController.kt index f91eb90..1ac6cc2 100644 --- a/src/main/kotlin/com/mjucow/eatda/presentation/store/StoreController.kt +++ b/src/main/kotlin/com/mjucow/eatda/presentation/store/StoreController.kt @@ -43,11 +43,11 @@ class StoreController( @GetMapping @ResponseStatus(HttpStatus.OK) override fun findAllByCategoryIdAndCursor( - @RequestParam("storeId", required = false) storeId: Long?, + @RequestParam("cursor", required = false) cursor: Long?, @RequestParam("categoryId", required = false) categoryId: Long?, @RequestParam("pageSize", required = false, defaultValue = "20") pageSize: Int, ): ApiResponse> { - val results = storeQueryService.findAllByCategoryAndCursor(storeId, categoryId, pageSize) + val results = storeQueryService.findAllByCategoryAndCursor(cursor, categoryId, pageSize) val contents = results.subList(0, min(pageSize, results.size)) val hasNext = results.size > pageSize diff --git a/src/test/kotlin/com/mjucow/eatda/domain/store/service/query/StoreQueryServiceDataTest.kt b/src/test/kotlin/com/mjucow/eatda/domain/store/service/query/StoreQueryServiceDataTest.kt index ccaade9..8ad775f 100644 --- a/src/test/kotlin/com/mjucow/eatda/domain/store/service/query/StoreQueryServiceDataTest.kt +++ b/src/test/kotlin/com/mjucow/eatda/domain/store/service/query/StoreQueryServiceDataTest.kt @@ -68,7 +68,12 @@ class StoreQueryServiceDataTest : AbstractDataTest() { // given val pageSize = 2 val latestId = IntStream.range(0, pageSize * 2).mapToLong { - repository.save(Store(name = "validName$it", address = StoreMother.ADDRESS)).id + repository.save( + Store( + name = "validName$it", + address = StoreMother.ADDRESS + ) + ).id }.max().asLong // when @@ -84,11 +89,19 @@ class StoreQueryServiceDataTest : AbstractDataTest() { // given val pageSize = Store.MAX_NAME_LENGTH - 1 repeat(Store.MAX_NAME_LENGTH) { - repository.save(Store(name = "x".repeat(it + 1), address = StoreMother.ADDRESS)) + repository.save( + Store( + name = "x".repeat(it + 1), + address = StoreMother.ADDRESS + ) + ) } // when - val result = storeQueryService.findAllByCategoryAndCursor(id = (pageSize * 2).toLong(), size = pageSize) + val result = storeQueryService.findAllByCategoryAndCursor( + cursor = (pageSize * 2).toLong(), + size = pageSize + ) // then assertThat(result.size).isEqualTo(pageSize + 1) @@ -103,7 +116,10 @@ class StoreQueryServiceDataTest : AbstractDataTest() { val pageSize = 10 // when - val result = storeQueryService.findAllByCategoryAndCursor(id = storeId + 1, size = pageSize) + val result = storeQueryService.findAllByCategoryAndCursor( + cursor = storeId + 1, + size = pageSize + ) // then assertThat(result.size).isLessThan(pageSize) @@ -118,7 +134,10 @@ class StoreQueryServiceDataTest : AbstractDataTest() { repository.save(store) // when - val result = storeQueryService.findAllByCategoryAndCursor(id = store.id, size = pageSize) + val result = storeQueryService.findAllByCategoryAndCursor( + cursor = store.id, + size = pageSize + ) // then assertThat(result).isEmpty() @@ -137,7 +156,10 @@ class StoreQueryServiceDataTest : AbstractDataTest() { }.max().asLong // when - val result = storeQueryService.findAllByCategoryAndCursor(categoryId = category.id, size = pageSize) + val result = storeQueryService.findAllByCategoryAndCursor( + categoryId = category.id, + size = pageSize + ) // then assertThat(result).anyMatch { it.id == latestId } @@ -178,7 +200,7 @@ class StoreQueryServiceDataTest : AbstractDataTest() { // when val result = storeQueryService.findAllByCategoryAndCursor( categoryId = category.id, - id = storeId + 1, + cursor = storeId + 1, size = pageSize ) @@ -198,7 +220,7 @@ class StoreQueryServiceDataTest : AbstractDataTest() { // when val result = storeQueryService.findAllByCategoryAndCursor( categoryId = category.id, - id = store.id, + cursor = store.id, size = 10 ) diff --git a/src/test/kotlin/com/mjucow/eatda/presentation/store/StoreControllerMvcTest.kt b/src/test/kotlin/com/mjucow/eatda/presentation/store/StoreControllerMvcTest.kt index 8aeaa66..e96a262 100644 --- a/src/test/kotlin/com/mjucow/eatda/presentation/store/StoreControllerMvcTest.kt +++ b/src/test/kotlin/com/mjucow/eatda/presentation/store/StoreControllerMvcTest.kt @@ -49,7 +49,10 @@ class StoreControllerMvcTest : AbstractMockMvcTest() { // given val entityId = 1L every { storeCommandService.create(any()) } returns entityId - val command = StoreCreateCommand(name = StoreMother.NAME, address = StoreMother.ADDRESS) + val command = StoreCreateCommand( + name = StoreMother.NAME, + address = StoreMother.ADDRESS + ) val content = objectMapper.writeValueAsString(command) // when & then @@ -95,7 +98,7 @@ class StoreControllerMvcTest : AbstractMockMvcTest() { // when & then mockMvc.perform( RestDocumentationRequestBuilders.get( - "$BASE_URI?storeId={storeId}&size={size}&categoryId={categoryId}", + "$BASE_URI?cursor={cursor}&size={size}&categoryId={categoryId}", storeDtos.size + 1, pageSize, null @@ -114,7 +117,7 @@ class StoreControllerMvcTest : AbstractMockMvcTest() { .tag("store") .description("커서 기반 카테고리 가게 조회") .queryParameters( - ResourceDocumentation.parameterWithName("storeId").description("조회한 마지막 가게 식별자").optional(), + ResourceDocumentation.parameterWithName("cursor").description("조회한 마지막 가게 식별자").optional(), ResourceDocumentation.parameterWithName("categoryId").description("조회하는 가게의 카테고리의 식별자").optional(), ResourceDocumentation.parameterWithName("size").description("조회할 페이지 사이즈").optional() ) @@ -154,7 +157,7 @@ class StoreControllerMvcTest : AbstractMockMvcTest() { // when & then mockMvc.perform( RestDocumentationRequestBuilders.get( - "$BASE_URI?storeId={storeId}&size={size}&categoryId={categoryId}", + "$BASE_URI?cursor={cursor}&size={size}&categoryId={categoryId}", storeDtos.size + 1, pageSize, 1