diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/content/AudioContentRepository.kt b/src/main/kotlin/kr/co/vividnext/sodalive/content/AudioContentRepository.kt index 1a02e7f..c484bd9 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/content/AudioContentRepository.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/content/AudioContentRepository.kt @@ -166,11 +166,7 @@ class AudioContentQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) where = where.and(audioContent.isAdult.isFalse) } - if (categoryId > 0) { - where = where.and(categoryContent.category.id.eq(categoryId)) - } - - return queryFactory + var select = queryFactory .select( QGetAudioContentListItem( audioContent.id, @@ -187,21 +183,43 @@ class AudioContentQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) ) ) .from(audioContent) - .leftJoin(categoryContent) - .on(audioContent.id.eq(categoryContent.content.id).and(categoryContent.isActive.ne(false))) .leftJoin(pinContent) .on(audioContent.id.eq(pinContent.content.id).and(pinContent.isActive.ne(false))) - .where(where) + + select = if (categoryId > 0) { + select + .leftJoin(categoryContent) + .on(audioContent.id.eq(categoryContent.content.id).and(categoryContent.isActive.ne(false))) + .where(where.and(categoryContent.category.id.eq(categoryId))) + } else { + select.where(where) + } + + select = select .offset(offset) .limit(limit) - .orderBy( - pinContent.isActive.desc(), - pinContent.updatedAt.desc(), - orderBy, - audioContent.updatedAt.desc(), - audioContent.id.desc() - ) - .fetch() + + select = if (categoryId > 0) { + select + .orderBy( + pinContent.isActive.desc(), + pinContent.updatedAt.desc(), + orderBy, + categoryContent.updatedAt.desc(), + audioContent.id.desc() + ) + } else { + select + .orderBy( + pinContent.isActive.desc(), + pinContent.updatedAt.desc(), + orderBy, + audioContent.updatedAt.desc(), + audioContent.id.desc() + ) + } + + return select.fetch() } override fun findTotalCountByCreatorId( @@ -219,18 +237,20 @@ class AudioContentQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) where = where.and(audioContent.isAdult.isFalse) } - if (categoryId > 0) { - where = where.and(categoryContent.category.id.eq(categoryId)) - } - - return queryFactory + var select = queryFactory .select(audioContent.id) .from(audioContent) - .leftJoin(categoryContent) - .on(audioContent.id.eq(categoryContent.content.id).and(categoryContent.isActive.ne(false))) - .where(where) - .fetch() - .size + + select = if (categoryId > 0) { + select + .leftJoin(categoryContent) + .on(audioContent.id.eq(categoryContent.content.id).and(categoryContent.isActive.ne(false))) + .where(where.and(categoryContent.category.id.eq(categoryId))) + } else { + select.where(where) + } + + return select.fetch().size } override fun getCreatorOtherContentList(