diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/content/category/CategoryController.kt b/src/main/kotlin/kr/co/vividnext/sodalive/content/category/CategoryController.kt index 724408e..ac308bc 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/content/category/CategoryController.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/content/category/CategoryController.kt @@ -6,10 +6,12 @@ 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.GetMapping 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 +import org.springframework.web.bind.annotation.RequestParam import org.springframework.web.bind.annotation.RestController @RestController @@ -36,4 +38,14 @@ class CategoryController(private val service: CategoryService) { ApiResponse.ok(service.deleteCategory(categoryId = categoryId, member = member)) } + + @GetMapping + fun getCategoryList( + @RequestParam creatorId: Long, + @AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member? + ) = run { + if (member == null) throw SodaException("로그인 정보를 확인해주세요.") + + ApiResponse.ok(service.getCategoryList(creatorId = creatorId, memberId = member.id!!)) + } } diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/content/category/CategoryRepository.kt b/src/main/kotlin/kr/co/vividnext/sodalive/content/category/CategoryRepository.kt index c3b3c2f..eacc9bd 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/content/category/CategoryRepository.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/content/category/CategoryRepository.kt @@ -10,6 +10,8 @@ interface CategoryQueryRepository { fun findByTitleAndMemberId(title: String, memberId: Long): Category? fun findByIdAndMemberId(categoryId: Long, memberId: Long): Category? + + fun findByCreatorId(creatorId: Long): List } class CategoryQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : CategoryQueryRepository { @@ -32,4 +34,12 @@ class CategoryQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : C ) .fetchFirst() } + + override fun findByCreatorId(creatorId: Long): List { + return queryFactory + .select(QGetCategoryListResponse(category.id, category.title)) + .from(category) + .where(category.member.id.eq(creatorId)) + .fetch() + } } diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/content/category/CategoryService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/content/category/CategoryService.kt index 7b44133..3265f70 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/content/category/CategoryService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/content/category/CategoryService.kt @@ -3,6 +3,7 @@ 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 kr.co.vividnext.sodalive.member.block.BlockMemberRepository import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @@ -10,6 +11,7 @@ import org.springframework.transaction.annotation.Transactional class CategoryService( private val repository: CategoryRepository, private val contentRepository: AudioContentRepository, + private val blockMemberRepository: BlockMemberRepository, private val categoryContentRepository: CategoryContentRepository ) { @Transactional @@ -47,4 +49,11 @@ class CategoryService( categoryContentRepository.deleteByCategoryId(categoryId = categoryId) } + + fun getCategoryList(creatorId: Long, memberId: Long): List { + val isBlocked = blockMemberRepository.isBlocked(blockedMemberId = memberId, memberId = creatorId) + if (isBlocked) throw SodaException("잘못된 접근입니다.") + + return repository.findByCreatorId(creatorId = creatorId) + } } diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/content/category/GetCategoryListResponse.kt b/src/main/kotlin/kr/co/vividnext/sodalive/content/category/GetCategoryListResponse.kt new file mode 100644 index 0000000..3e575c8 --- /dev/null +++ b/src/main/kotlin/kr/co/vividnext/sodalive/content/category/GetCategoryListResponse.kt @@ -0,0 +1,8 @@ +package kr.co.vividnext.sodalive.content.category + +import com.querydsl.core.annotations.QueryProjection + +data class GetCategoryListResponse @QueryProjection constructor( + val categoryId: Long, + val category: String +)