test #123

Merged
klaus merged 9 commits from test into main 2024-02-05 02:12:10 +00:00
4 changed files with 45 additions and 3 deletions
Showing only changes of commit 8be2ec9319 - Show all commits

View File

@ -8,6 +8,7 @@ interface CategoryContentRepository : JpaRepository<CategoryContent, Long>, Cate
interface CategoryContentQueryRepository {
fun findByContentIdAndCategoryId(contentId: Long, categoryId: Long): CategoryContent?
fun deleteByCategoryId(categoryId: Long)
}
class CategoryContentQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : CategoryContentQueryRepository {
@ -20,4 +21,12 @@ class CategoryContentQueryRepositoryImpl(private val queryFactory: JPAQueryFacto
)
.fetchFirst()
}
override fun deleteByCategoryId(categoryId: Long) {
queryFactory
.update(categoryContent)
.set(categoryContent.isActive, false)
.where(categoryContent.category.id.eq(categoryId))
.execute()
}
}

View File

@ -5,6 +5,8 @@ import kr.co.vividnext.sodalive.common.SodaException
import kr.co.vividnext.sodalive.member.Member
import org.springframework.security.access.prepost.PreAuthorize
import org.springframework.security.core.annotation.AuthenticationPrincipal
import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
@ -21,8 +23,17 @@ class CategoryController(private val service: CategoryService) {
) = run {
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
ApiResponse.ok(
service.createCategory(request = request, member = member)
)
ApiResponse.ok(service.createCategory(request = request, member = member))
}
@DeleteMapping("/{id}")
@PreAuthorize("hasRole('CREATOR')")
fun deleteCategory(
@PathVariable("id") categoryId: Long,
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
) = run {
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
ApiResponse.ok(service.deleteCategory(categoryId = categoryId, member = member))
}
}

View File

@ -8,6 +8,8 @@ interface CategoryRepository : JpaRepository<Category, Long>, CategoryQueryRepos
interface CategoryQueryRepository {
fun findByTitleAndMemberId(title: String, memberId: Long): Category?
fun findByIdAndMemberId(categoryId: Long, memberId: Long): Category?
}
class CategoryQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : CategoryQueryRepository {
@ -20,4 +22,14 @@ class CategoryQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : C
)
.fetchFirst()
}
override fun findByIdAndMemberId(categoryId: Long, memberId: Long): Category? {
return queryFactory
.selectFrom(category)
.where(
category.id.eq(categoryId)
.and(category.member.id.eq(memberId))
)
.fetchFirst()
}
}

View File

@ -1,5 +1,6 @@
package kr.co.vividnext.sodalive.content.category
import kr.co.vividnext.sodalive.common.SodaException
import kr.co.vividnext.sodalive.content.AudioContentRepository
import kr.co.vividnext.sodalive.member.Member
import org.springframework.stereotype.Service
@ -37,4 +38,13 @@ class CategoryService(
categoryContent.isActive = true
}
}
@Transactional
fun deleteCategory(categoryId: Long, member: Member) {
val category = repository.findByIdAndMemberId(categoryId = categoryId, memberId = member.id!!)
?: throw SodaException("잘못된 요청입니다.")
category.isActive = false
categoryContentRepository.deleteByCategoryId(categoryId = categoryId)
}
}