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"), }