Skip to content

Commit

Permalink
[feat #187] 포킷 내보내기 API (#188)
Browse files Browse the repository at this point in the history
* feat : SharedCategory 삭제 여부 필드 추가

* feat : 포킷 내보내기 API

* feat : 포킷 내보내기 비즈니스 로직
  • Loading branch information
dlswns2480 authored Nov 28, 2024
1 parent 223496e commit 40f748c
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Unit> {
return categoryUseCase.resignUser(user.id, categoryId, resignUserId)
.wrapUnit()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,25 @@ 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
)
}
}

internal fun SharedCategoryEntity.toDomain() = SharedCategory(
id = this.id,
userId = this.userId,
categoryId = this.categoryId
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@ package com.pokit.out.persistence.category.persist
import org.springframework.data.jpa.repository.JpaRepository

interface SharedCategoryRepository : JpaRepository<SharedCategoryEntity, Long> {
fun findByUserIdAndCategoryId(userId: Long, categoryId: Long): SharedCategoryEntity?
fun findByUserIdAndCategoryIdAndIsDeleted(
userId: Long,
categoryId: Long,
isDeleted: Boolean
): SharedCategoryEntity?
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ interface SharedCategoryPort {
fun persist(sharedCategory: SharedCategory): SharedCategory

fun loadByUserIdAndCategoryId(userId: Long, categoryId: Long): SharedCategory?

fun delete(sharedCategory: SharedCategory)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<CategoryImage> =
categoryImagePort.loadAll()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),

}

0 comments on commit 40f748c

Please sign in to comment.