테마별 콘텐츠 가져오기 API
- 정렬기준 추가
This commit is contained in:
		| @@ -62,6 +62,7 @@ interface AudioContentQueryRepository { | ||||
|         cloudfrontHost: String, | ||||
|         memberId: Long, | ||||
|         theme: String = "", | ||||
|         sortType: SortType = SortType.NEWEST, | ||||
|         isAdult: Boolean = false, | ||||
|         offset: Long = 0, | ||||
|         limit: Long = 20 | ||||
| @@ -317,10 +318,17 @@ class AudioContentQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) | ||||
|         cloudfrontHost: String, | ||||
|         memberId: Long, | ||||
|         theme: String, | ||||
|         sortType: SortType, | ||||
|         isAdult: Boolean, | ||||
|         offset: Long, | ||||
|         limit: Long | ||||
|     ): List<GetAudioContentMainItem> { | ||||
|         val orderBy = when (sortType) { | ||||
|             SortType.NEWEST -> audioContent.releaseDate.desc() | ||||
|             SortType.PRICE_HIGH -> audioContent.price.desc() | ||||
|             SortType.PRICE_LOW -> audioContent.price.asc() | ||||
|         } | ||||
|  | ||||
|         var where = audioContent.isActive.isTrue | ||||
|             .and( | ||||
|                 audioContent.releaseDate.isNull | ||||
| @@ -355,7 +363,7 @@ class AudioContentQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) | ||||
|             .where(where) | ||||
|             .offset(offset) | ||||
|             .limit(limit) | ||||
|             .orderBy(audioContent.releaseDate.desc()) | ||||
|             .orderBy(orderBy) | ||||
|             .fetch() | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -2,6 +2,7 @@ package kr.co.vividnext.sodalive.content.theme | ||||
|  | ||||
| import kr.co.vividnext.sodalive.common.ApiResponse | ||||
| import kr.co.vividnext.sodalive.common.SodaException | ||||
| import kr.co.vividnext.sodalive.content.SortType | ||||
| import kr.co.vividnext.sodalive.member.Member | ||||
| import org.springframework.data.domain.Pageable | ||||
| import org.springframework.security.access.prepost.PreAuthorize | ||||
| @@ -9,6 +10,7 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal | ||||
| import org.springframework.web.bind.annotation.GetMapping | ||||
| import org.springframework.web.bind.annotation.PathVariable | ||||
| import org.springframework.web.bind.annotation.RequestMapping | ||||
| import org.springframework.web.bind.annotation.RequestParam | ||||
| import org.springframework.web.bind.annotation.RestController | ||||
|  | ||||
| @RestController | ||||
| @@ -27,6 +29,7 @@ class AudioContentThemeController(private val service: AudioContentThemeService) | ||||
|     @GetMapping("/{id}/content") | ||||
|     fun getContentByTheme( | ||||
|         @PathVariable id: Long, | ||||
|         @RequestParam("sort-type", required = false) sortType: SortType = SortType.NEWEST, | ||||
|         @AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?, | ||||
|         pageable: Pageable | ||||
|     ) = run { | ||||
| @@ -35,6 +38,7 @@ class AudioContentThemeController(private val service: AudioContentThemeService) | ||||
|         ApiResponse.ok( | ||||
|             service.getContentByTheme( | ||||
|                 themeId = id, | ||||
|                 sortType = sortType, | ||||
|                 member = member, | ||||
|                 offset = pageable.offset, | ||||
|                 limit = pageable.pageSize.toLong() | ||||
|   | ||||
| @@ -2,6 +2,7 @@ package kr.co.vividnext.sodalive.content.theme | ||||
|  | ||||
| import kr.co.vividnext.sodalive.common.SodaException | ||||
| import kr.co.vividnext.sodalive.content.AudioContentRepository | ||||
| import kr.co.vividnext.sodalive.content.SortType | ||||
| import kr.co.vividnext.sodalive.content.theme.content.GetContentByThemeResponse | ||||
| import kr.co.vividnext.sodalive.member.Member | ||||
| import kr.co.vividnext.sodalive.member.block.BlockMemberRepository | ||||
| @@ -24,7 +25,13 @@ class AudioContentThemeService( | ||||
|     } | ||||
|  | ||||
|     @Transactional(readOnly = true) | ||||
|     fun getContentByTheme(themeId: Long, member: Member, offset: Long, limit: Long): GetContentByThemeResponse { | ||||
|     fun getContentByTheme( | ||||
|         themeId: Long, | ||||
|         sortType: SortType, | ||||
|         member: Member, | ||||
|         offset: Long, | ||||
|         limit: Long | ||||
|     ): GetContentByThemeResponse { | ||||
|         val theme = queryRepository.findThemeByIdAndActive(themeId) | ||||
|             ?: throw SodaException("잘못된 요청입니다.") | ||||
|  | ||||
| @@ -32,6 +39,7 @@ class AudioContentThemeService( | ||||
|             cloudfrontHost = imageHost, | ||||
|             memberId = member.id!!, | ||||
|             theme = theme.theme, | ||||
|             sortType = sortType, | ||||
|             isAdult = member.auth != null, | ||||
|             offset = offset, | ||||
|             limit = limit | ||||
|   | ||||
		Reference in New Issue
	
	Block a user