From ec506e7a19754d800bd9ada56ba6ad26f08d998b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=9D=B8=EC=A4=80?= <54973090+dlswns2480@users.noreply.github.com> Date: Fri, 20 Dec 2024 23:42:16 +0900 Subject: [PATCH] =?UTF-8?q?[feat=20#208]=20=ED=8F=AC=ED=82=B7=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20api=20v2=20(#209)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat : 포킷 목록 조회 API Ver2 * feat : 포킷 목록 조회 비즈니스 로직 ver2 * feat : 공유 포킷 조회 쿼리 구현 * feat : 카테고리 Id 리스트로 조회 쿼리 구현 --- .../pokit/category/v2/CategoryControllerV2.kt | 25 ++++++++++++++++++- .../category/impl/CategoryAdapter.kt | 5 ++++ .../category/impl/SharedCategoryAdapter.kt | 5 ++++ .../category/persist/CategoryRepository.kt | 5 ++++ .../persist/SharedCategoryRepository.kt | 2 ++ .../pokit/category/port/in/CategoryUseCase.kt | 2 ++ .../pokit/category/port/out/CategoryPort.kt | 1 + .../category/port/out/SharedCategoryPort.kt | 2 ++ .../category/port/service/CategoryService.kt | 7 ++++++ 9 files changed, 53 insertions(+), 1 deletion(-) diff --git a/adapters/in-web/src/main/kotlin/com/pokit/category/v2/CategoryControllerV2.kt b/adapters/in-web/src/main/kotlin/com/pokit/category/v2/CategoryControllerV2.kt index 4e7842fb..9fbc8338 100644 --- a/adapters/in-web/src/main/kotlin/com/pokit/category/v2/CategoryControllerV2.kt +++ b/adapters/in-web/src/main/kotlin/com/pokit/category/v2/CategoryControllerV2.kt @@ -2,16 +2,22 @@ package com.pokit.category.v2 import com.pokit.auth.config.ErrorOperation import com.pokit.auth.model.PrincipalUser +import com.pokit.category.dto.CategoriesResponse import com.pokit.category.exception.CategoryErrorCode import com.pokit.category.port.`in`.CategoryUseCase import com.pokit.category.v1.dto.response.CategoryResponse import com.pokit.category.v1.dto.response.toResponse import com.pokit.category.v2.dto.request.CreateCategoryRequestV2 import com.pokit.category.v2.dto.request.toDto +import com.pokit.common.dto.SliceResponseDto import com.pokit.common.wrapper.ResponseWrapper.wrapOk +import com.pokit.common.wrapper.ResponseWrapper.wrapSlice import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.tags.Tag import jakarta.validation.Valid +import org.springframework.data.domain.Pageable +import org.springframework.data.domain.Sort +import org.springframework.data.web.PageableDefault import org.springframework.http.ResponseEntity import org.springframework.security.core.annotation.AuthenticationPrincipal import org.springframework.web.bind.annotation.* @@ -34,7 +40,7 @@ class CategoryControllerV2( .wrapOk() } - @Operation(summary = "포킷 추가 API Ver2") + @Operation(summary = "포킷 수정 API Ver2") @ErrorOperation(CategoryErrorCode::class) @PatchMapping("/{categoryId}") fun updateCategory( @@ -47,4 +53,21 @@ class CategoryControllerV2( .wrapOk() } + @Operation(summary = "포킷 목록 조회 API Ver2") + @GetMapping + fun getCategory( + @AuthenticationPrincipal user: PrincipalUser, + @PageableDefault( + page = 0, + size = 10, + sort = ["createdAt"], + direction = Sort.Direction.DESC + ) pageable: Pageable, + @RequestParam(defaultValue = "true") filterUncategorized: Boolean + ): ResponseEntity> { + return categoryUseCase.getCategoriesV2(user.id, pageable, filterUncategorized) + .wrapSlice() + .wrapOk() + } + } diff --git a/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/category/impl/CategoryAdapter.kt b/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/category/impl/CategoryAdapter.kt index aaafab04..5557e5ef 100644 --- a/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/category/impl/CategoryAdapter.kt +++ b/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/category/impl/CategoryAdapter.kt @@ -49,4 +49,9 @@ class CategoryAdapter( ?.toDomain() } + override fun loadAllInId(categoryIds: List, pageable: Pageable): Slice { + return categoryRepository.findAllByIdInAndDeleted(categoryIds, pageable, false) + .map { it.toDomain() } + } + } diff --git a/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/category/impl/SharedCategoryAdapter.kt b/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/category/impl/SharedCategoryAdapter.kt index 1a450757..80db96aa 100644 --- a/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/category/impl/SharedCategoryAdapter.kt +++ b/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/category/impl/SharedCategoryAdapter.kt @@ -36,4 +36,9 @@ class SharedCategoryAdapter( false )?.toDomain() } + + override fun loadByUserId(userId: Long): List { + return sharedCategoryRepository.findByUserIdAndIsDeleted(userId, false) + .map { it.toDomain() } + } } diff --git a/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/category/persist/CategoryRepository.kt b/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/category/persist/CategoryRepository.kt index b5f7ecb4..4d36ff83 100644 --- a/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/category/persist/CategoryRepository.kt +++ b/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/category/persist/CategoryRepository.kt @@ -12,4 +12,9 @@ interface CategoryRepository : JpaRepository { fun countByUserIdAndDeleted(userId: Long, deleted: Boolean): Int fun findByIdAndOpenTypeAndDeleted(id: Long, openType: OpenType, deleted: Boolean): CategoryEntity? fun findByNameAndUserId(name: String, userId: Long): CategoryEntity? + fun findAllByIdInAndDeleted( + categoryIds: List, + pageable: Pageable, + isDeleted: Boolean + ): Slice } diff --git a/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/category/persist/SharedCategoryRepository.kt b/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/category/persist/SharedCategoryRepository.kt index ffda33cc..70ac6851 100644 --- a/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/category/persist/SharedCategoryRepository.kt +++ b/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/category/persist/SharedCategoryRepository.kt @@ -13,4 +13,6 @@ interface SharedCategoryRepository : JpaRepository { categoryId: Long, deleted: Boolean ): SharedCategoryEntity? + + fun findByUserIdAndIsDeleted(userId: Long, isDeleted: Boolean): List } diff --git a/application/src/main/kotlin/com/pokit/category/port/in/CategoryUseCase.kt b/application/src/main/kotlin/com/pokit/category/port/in/CategoryUseCase.kt index c17ba025..2d64fde9 100644 --- a/application/src/main/kotlin/com/pokit/category/port/in/CategoryUseCase.kt +++ b/application/src/main/kotlin/com/pokit/category/port/in/CategoryUseCase.kt @@ -21,4 +21,6 @@ interface CategoryUseCase { fun acceptCategory(userId: Long, categoryId: Long) fun resignUser(userId: Long, categoryId: Long, resignUserId: Long) fun outCategory(userId: Long, categoryId: Long) + fun getCategoriesV2(userId: Long, pageable: Pageable, filterUncategorized: Boolean): Slice + } diff --git a/application/src/main/kotlin/com/pokit/category/port/out/CategoryPort.kt b/application/src/main/kotlin/com/pokit/category/port/out/CategoryPort.kt index c0f30520..0bdc5046 100644 --- a/application/src/main/kotlin/com/pokit/category/port/out/CategoryPort.kt +++ b/application/src/main/kotlin/com/pokit/category/port/out/CategoryPort.kt @@ -15,4 +15,5 @@ interface CategoryPort { fun countByUserId(userId: Long): Int fun loadByIdAndOpenType(id: Long, openType: OpenType): Category? fun loadByNameAndUserId(categoryName: String, userId: Long): Category? + fun loadAllInId(categoryIds: List, pageable: Pageable): Slice } diff --git a/application/src/main/kotlin/com/pokit/category/port/out/SharedCategoryPort.kt b/application/src/main/kotlin/com/pokit/category/port/out/SharedCategoryPort.kt index ff0145f5..8aa2d46d 100644 --- a/application/src/main/kotlin/com/pokit/category/port/out/SharedCategoryPort.kt +++ b/application/src/main/kotlin/com/pokit/category/port/out/SharedCategoryPort.kt @@ -10,4 +10,6 @@ interface SharedCategoryPort { fun delete(sharedCategory: SharedCategory) fun loadFirstByCategoryId(categoryId: Long): SharedCategory? + + fun loadByUserId(userId: Long): List } diff --git a/application/src/main/kotlin/com/pokit/category/port/service/CategoryService.kt b/application/src/main/kotlin/com/pokit/category/port/service/CategoryService.kt index a9fcdc1b..c0b492dd 100644 --- a/application/src/main/kotlin/com/pokit/category/port/service/CategoryService.kt +++ b/application/src/main/kotlin/com/pokit/category/port/service/CategoryService.kt @@ -217,6 +217,13 @@ class CategoryService( categoryPort.persist(category) } + override fun getCategoriesV2(userId: Long, pageable: Pageable, filterUncategorized: Boolean): Slice { + val sharedCategories = sharedCategoryPort.loadByUserId(userId) + val categoryIds = sharedCategories.map { it.categoryId } + val categories = categoryPort.loadAllInId(categoryIds, pageable) + return categories.map { it.toCategoriesResponse() } + } + override fun getAllCategoryImages(): List = categoryImagePort.loadAll()