Skip to content

Commit

Permalink
feat : 포킷 공유 조회, 복제 플로우에 카테고리 이미지 정보 추가 (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
dlswns2480 authored Aug 24, 2024
1 parent bd197e2 commit 5b3da1d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ class CategoryShareController(
@AuthenticationPrincipal user: PrincipalUser,
@RequestBody request: DuplicateCategoryRequest,
): ResponseEntity<Unit> =
categoryUseCase.duplicateCategory(request.originCategoryId, request.categoryName, user.id)
categoryUseCase.duplicateCategory(
request.originCategoryId,
request.categoryName,
user.id,
request.categoryImageId
)
.wrapOk()

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ data class DuplicateCategoryRequest (
val originCategoryId: Long,
@field:Size(min = 1, max = 10, message = "최대 10자까지 입력 가능합니다.")
val categoryName: String,
val categoryImageId: Int
)
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,17 @@ 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 {
return SharedCategoryResponse(
categoryId = category.categoryId,
categoryName = category.categoryName,
contentCount = category.contentCount,
categoryImageId = category.categoryImage.imageId,
categoryImageUrl = category.categoryImage.imageUrl
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
}

Expand Down
5 changes: 3 additions & 2 deletions domain/src/main/kotlin/com/pokit/category/model/Category.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}

0 comments on commit 5b3da1d

Please sign in to comment.