Skip to content

Commit

Permalink
feat : 카테고리 목록 조회 쿼리 정렬 조건 변경 (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
dlswns2480 authored Jan 12, 2025
1 parent 45621f8 commit f7c3385
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import com.pokit.category.model.OpenType
import org.springframework.data.domain.Pageable
import org.springframework.data.domain.Slice
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.query.Param

interface CategoryRepository : JpaRepository<CategoryEntity, Long> {
fun existsByNameAndUserIdAndDeleted(name: String, userId: Long, deleted: Boolean): Boolean
Expand All @@ -12,9 +14,19 @@ interface CategoryRepository : JpaRepository<CategoryEntity, Long> {
fun countByUserIdAndDeleted(userId: Long, deleted: Boolean): Int
fun findByIdAndOpenTypeAndDeleted(id: Long, openType: OpenType, deleted: Boolean): CategoryEntity?
fun findByNameAndUserId(name: String, userId: Long): CategoryEntity?

@Query(
"""
select ca from CategoryEntity ca
join ContentEntity co on co.categoryId = ca.id
where ca.id in :categoryIds and ca.deleted = :isDeleted
group by ca.id
order by max(co.createdAt) desc
"""
)
fun findAllByIdInAndDeleted(
categoryIds: List<Long>,
@Param("categoryIds") categoryIds: List<Long>,
pageable: Pageable,
isDeleted: Boolean
@Param("isDeleted") isDeleted: Boolean
): Slice<CategoryEntity>
}

0 comments on commit f7c3385

Please sign in to comment.