diff --git a/adapters/in-web/src/main/kotlin/com/pokit/category/CategoryShareController.kt b/adapters/in-web/src/main/kotlin/com/pokit/category/CategoryShareController.kt index 7689874..f56c4d4 100644 --- a/adapters/in-web/src/main/kotlin/com/pokit/category/CategoryShareController.kt +++ b/adapters/in-web/src/main/kotlin/com/pokit/category/CategoryShareController.kt @@ -55,7 +55,12 @@ class CategoryShareController( @AuthenticationPrincipal user: PrincipalUser, @RequestBody request: DuplicateCategoryRequest, ): ResponseEntity = - categoryUseCase.duplicateCategory(request.originCategoryId, request.categoryName, user.id) + categoryUseCase.duplicateCategory( + request.originCategoryId, + request.categoryName, + user.id, + request.categoryImageId + ) .wrapOk() } diff --git a/adapters/in-web/src/main/kotlin/com/pokit/category/dto/request/DuplicateCategoryRequest.kt b/adapters/in-web/src/main/kotlin/com/pokit/category/dto/request/DuplicateCategoryRequest.kt index 984bdfc..7963de6 100644 --- a/adapters/in-web/src/main/kotlin/com/pokit/category/dto/request/DuplicateCategoryRequest.kt +++ b/adapters/in-web/src/main/kotlin/com/pokit/category/dto/request/DuplicateCategoryRequest.kt @@ -6,4 +6,5 @@ data class DuplicateCategoryRequest ( val originCategoryId: Long, @field:Size(min = 1, max = 10, message = "최대 10자까지 입력 가능합니다.") val categoryName: String, + val categoryImageId: Int ) diff --git a/adapters/in-web/src/main/kotlin/com/pokit/category/dto/response/SharedContentsResponse.kt b/adapters/in-web/src/main/kotlin/com/pokit/category/dto/response/SharedContentsResponse.kt index 503c71a..24ee61a 100644 --- a/adapters/in-web/src/main/kotlin/com/pokit/category/dto/response/SharedContentsResponse.kt +++ b/adapters/in-web/src/main/kotlin/com/pokit/category/dto/response/SharedContentsResponse.kt @@ -53,6 +53,8 @@ data class SharedCategoryResponse( val categoryId: Long = 0L, var categoryName: String, var contentCount: Int = 0, + val categoryImageId: Int, + val categoryImageUrl: String ) { companion object { fun of(category: Category): SharedCategoryResponse { @@ -60,6 +62,8 @@ data class SharedCategoryResponse( categoryId = category.categoryId, categoryName = category.categoryName, contentCount = category.contentCount, + categoryImageId = category.categoryImage.imageId, + categoryImageUrl = category.categoryImage.imageUrl ) } } 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 2555efb..df33091 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 @@ -17,5 +17,5 @@ interface CategoryUseCase { fun getCategory(userId: Long, categoryId: Long): Category fun getSharedCategory(categoryId: Long, userId: Long): Category fun completeShare(categoryId: Long, userId: Long) - fun duplicateCategory(originCategoryId: Long, categoryName: String, userId: Long) + fun duplicateCategory(originCategoryId: Long, categoryName: String, userId: Long, categoryImageId: Int) } 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 47c5c19..5cf8d12 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 @@ -128,7 +128,12 @@ class CategoryService( } @Transactional - override fun duplicateCategory(originCategoryId: Long, categoryName: String, userId: Long) { + override fun duplicateCategory( + originCategoryId: Long, + categoryName: String, + userId: Long, + categoryImageId: Int + ) { val originCategory = categoryPort.loadByIdAndOpenType(originCategoryId, OpenType.PUBLIC) ?: throw NotFoundCustomException(CategoryErrorCode.NOT_FOUND_CATEGORY) @@ -143,8 +148,9 @@ class CategoryService( if (categoryPort.existsByNameAndUserId(categoryName, userId)) { throw AlreadyExistsException(CategoryErrorCode.SHARE_ALREADY_EXISTS_CATEGORY_NAME) } - - val newCategory = categoryPort.persist(originCategory.duplicate(categoryName, userId)) + val categoryImage = (categoryImagePort.loadById(categoryImageId) + ?: throw NotFoundCustomException(CategoryErrorCode.NOT_FOUND_CATEGORY_IMAGE)) + val newCategory = categoryPort.persist(originCategory.duplicate(categoryName, userId, categoryImage)) contentPort.duplicateContent(originCategoryId, newCategory.categoryId) } diff --git a/domain/src/main/kotlin/com/pokit/category/model/Category.kt b/domain/src/main/kotlin/com/pokit/category/model/Category.kt index 7c9f611..b8b4534 100644 --- a/domain/src/main/kotlin/com/pokit/category/model/Category.kt +++ b/domain/src/main/kotlin/com/pokit/category/model/Category.kt @@ -32,10 +32,11 @@ fun Category.toRemindCategory() = RemindCategory( categoryName = this.categoryName, ) -fun Category.duplicate(newCategoryName: String, userId: Long): Category { +fun Category.duplicate(newCategoryName: String, userId: Long, categoryImage: CategoryImage): Category { return this.copy( categoryId = 0L, userId = userId, - categoryName = newCategoryName + categoryName = newCategoryName, + categoryImage = categoryImage ) }