From 40f748c512cdd50cd525de5fb9d8b5d16296ac0f 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: Thu, 28 Nov 2024 14:06:59 +0900 Subject: [PATCH] =?UTF-8?q?[feat=20#187]=20=ED=8F=AC=ED=82=B7=20=EB=82=B4?= =?UTF-8?q?=EB=B3=B4=EB=82=B4=EA=B8=B0=20API=20(#188)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat : SharedCategory 삭제 여부 필드 추가 * feat : 포킷 내보내기 API * feat : 포킷 내보내기 비즈니스 로직 --- .../com/pokit/category/CategoryShareController.kt | 11 +++++++++++ .../category/impl/SharedCategoryAdapter.kt | 12 ++++++++++-- .../category/persist/SharedCategoryEntity.kt | 9 +++++++++ .../category/persist/SharedCategoryRepository.kt | 6 +++++- .../com/pokit/category/port/in/CategoryUseCase.kt | 1 + .../pokit/category/port/out/SharedCategoryPort.kt | 2 ++ .../pokit/category/port/service/CategoryService.kt | 9 +++++++++ .../pokit/category/exception/CategoryErrorCode.kt | 1 + 8 files changed, 48 insertions(+), 3 deletions(-) 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 7d0446f8..0fe2e501 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 @@ -75,4 +75,15 @@ class CategoryShareController( .wrapUnit() } + @Operation(summary = "포킷 내보내기 API") + @PostMapping("/resign/{categoryId}/{resignUserId}") + fun resignUserOfCategory( + @AuthenticationPrincipal user: PrincipalUser, + @PathVariable categoryId: Long, + @PathVariable resignUserId: Long, + ): ResponseEntity { + return categoryUseCase.resignUser(user.id, categoryId, resignUserId) + .wrapUnit() + } + } 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 c67d0c11..29884166 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 @@ -5,6 +5,7 @@ import com.pokit.category.port.out.SharedCategoryPort import com.pokit.out.persistence.category.persist.SharedCategoryEntity import com.pokit.out.persistence.category.persist.SharedCategoryRepository import com.pokit.out.persistence.category.persist.toDomain +import org.springframework.data.repository.findByIdOrNull import org.springframework.stereotype.Repository @Repository @@ -17,8 +18,15 @@ class SharedCategoryAdapter( } override fun loadByUserIdAndCategoryId(userId: Long, categoryId: Long): SharedCategory? { - return sharedCategoryRepository.findByUserIdAndCategoryId(userId, categoryId) - ?.toDomain() + return sharedCategoryRepository.findByUserIdAndCategoryIdAndIsDeleted( + userId, + categoryId, + false + )?.toDomain() } + override fun delete(sharedCategory: SharedCategory) { + sharedCategoryRepository.findByIdOrNull(sharedCategory.id) + ?.delete() + } } diff --git a/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/category/persist/SharedCategoryEntity.kt b/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/category/persist/SharedCategoryEntity.kt index a9f984eb..6d911f8a 100644 --- a/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/category/persist/SharedCategoryEntity.kt +++ b/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/category/persist/SharedCategoryEntity.kt @@ -16,9 +16,17 @@ class SharedCategoryEntity( @Column(name = "category_id") val categoryId: Long, + + @Column(name = "is_deleted") + var isDeleted: Boolean = false ) : BaseEntity() { + fun delete() { + this.isDeleted = true + } + companion object { fun of(sharedCategory: SharedCategory) = SharedCategoryEntity( + id= sharedCategory.id, userId = sharedCategory.userId, categoryId = sharedCategory.categoryId ) @@ -26,6 +34,7 @@ class SharedCategoryEntity( } internal fun SharedCategoryEntity.toDomain() = SharedCategory( + id = this.id, userId = this.userId, categoryId = this.categoryId ) 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 41d04d13..a35329af 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 @@ -3,5 +3,9 @@ package com.pokit.out.persistence.category.persist import org.springframework.data.jpa.repository.JpaRepository interface SharedCategoryRepository : JpaRepository { - fun findByUserIdAndCategoryId(userId: Long, categoryId: Long): SharedCategoryEntity? + fun findByUserIdAndCategoryIdAndIsDeleted( + userId: Long, + categoryId: Long, + isDeleted: Boolean + ): SharedCategoryEntity? } 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 ab9adc57..52bd682a 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 @@ -19,4 +19,5 @@ interface CategoryUseCase { fun completeShare(categoryId: Long) fun duplicateCategory(originCategoryId: Long, categoryName: String, userId: Long, categoryImageId: Int) fun acceptCategory(userId: Long, categoryId: Long) + fun resignUser(userId: Long, categoryId: Long, resignUserId: Long) } 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 151e5042..5d9c37e7 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 @@ -6,4 +6,6 @@ interface SharedCategoryPort { fun persist(sharedCategory: SharedCategory): SharedCategory fun loadByUserIdAndCategoryId(userId: Long, categoryId: Long): SharedCategory? + + fun delete(sharedCategory: SharedCategory) } 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 f80bde59..9ad5f270 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 @@ -170,6 +170,15 @@ class CategoryService( sharedCategoryPort.persist(sharedCategory) } + @Transactional + override fun resignUser(userId: Long, categoryId: Long, resignUserId: Long) { + val category = categoryPort.loadByIdAndUserId(categoryId, userId) + ?: throw NotFoundCustomException(CategoryErrorCode.NOT_FOUND_CATEGORY) + val sharedCategory = (sharedCategoryPort.loadByUserIdAndCategoryId(resignUserId, category.categoryId) + ?: throw NotFoundCustomException(CategoryErrorCode.NEVER_ACCPTED)) + sharedCategoryPort.delete(sharedCategory) + } + override fun getAllCategoryImages(): List = categoryImagePort.loadAll() diff --git a/domain/src/main/kotlin/com/pokit/category/exception/CategoryErrorCode.kt b/domain/src/main/kotlin/com/pokit/category/exception/CategoryErrorCode.kt index 30d7a94c..1714f76b 100644 --- a/domain/src/main/kotlin/com/pokit/category/exception/CategoryErrorCode.kt +++ b/domain/src/main/kotlin/com/pokit/category/exception/CategoryErrorCode.kt @@ -15,5 +15,6 @@ enum class CategoryErrorCode( SHARE_ALREADY_EXISTS_CATEGORY("직접 생성한 포킷은 공유받을 수 없습니다.\n 다른 유저의 포킷을 공유받아보세요.", "CA_007"), NOT_FOUND_UNCATEGORIZED("사용자가 미분류 카테고리가 없습니다.(서버 에러)", "CA_008"), ALREADY_ACCEPTED("이미 초대를 수락한 포킷입니다.", "CA_009"), + NEVER_ACCPTED("해당 유저가 포킷에 초대된 이력이 없습니다.", "CA_0010"), }