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