콘텐츠 카테고리
- 카테고리 조회 API 추가
This commit is contained in:
		| @@ -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!!)) | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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<GetCategoryListResponse> | ||||
| } | ||||
|  | ||||
| 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<GetCategoryListResponse> { | ||||
|         return queryFactory | ||||
|             .select(QGetCategoryListResponse(category.id, category.title)) | ||||
|             .from(category) | ||||
|             .where(category.member.id.eq(creatorId)) | ||||
|             .fetch() | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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<GetCategoryListResponse> { | ||||
|         val isBlocked = blockMemberRepository.isBlocked(blockedMemberId = memberId, memberId = creatorId) | ||||
|         if (isBlocked) throw SodaException("잘못된 접근입니다.") | ||||
|  | ||||
|         return repository.findByCreatorId(creatorId = creatorId) | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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 | ||||
| ) | ||||
		Reference in New Issue
	
	Block a user