diff --git a/domain/src/main/kotlin/com/oksusu/susu/domain/common/extension/QueryDslExtension.kt b/domain/src/main/kotlin/com/oksusu/susu/domain/common/extension/QueryDslExtension.kt index 0cd2ed1e..e9ecad57 100644 --- a/domain/src/main/kotlin/com/oksusu/susu/domain/common/extension/QueryDslExtension.kt +++ b/domain/src/main/kotlin/com/oksusu/susu/domain/common/extension/QueryDslExtension.kt @@ -18,29 +18,27 @@ import org.springframework.data.jpa.repository.support.Querydsl import java.time.LocalDateTime fun Querydsl?.execute(query: JPAQuery, pageable: Pageable): Page { - return this.takeUnless { querydsl -> querydsl == null } - ?.let { queryDsl -> - queryDsl.applyPagination(pageable, query).run { - PageImpl(this.fetch(), pageable, this.fetchCount()) - } - } ?: throw SusuException(ErrorCode.QUERY_DSL_NOT_EXISTS_ERROR) + return this?.let { queryDsl -> + queryDsl.applyPagination(pageable, query).run { + PageImpl(this.fetch(), pageable, this.fetchCount()) + } + } ?: throw SusuException(ErrorCode.QUERY_DSL_NOT_EXISTS_ERROR) } fun Querydsl?.executeSlice(query: JPAQuery, pageable: Pageable): Slice { - return this.takeUnless { querydsl -> querydsl == null } - ?.let { queryDsl -> - queryDsl.applyPagination(pageable, query).run { - this.limit(pageable.pageSize + 1L) - .fetch() - }.run { - var hasNext = false - if (this.size > pageable.pageSize) { - hasNext = true - this.removeAt(pageable.pageSize) - } - SliceImpl(this, pageable, hasNext) + return this?.let { queryDsl -> + queryDsl.applyPagination(pageable, query).run { + this.limit(pageable.pageSize + 1L) + .fetch() + }.run { + var hasNext = false + if (this.size > pageable.pageSize) { + hasNext = true + this.removeAt(pageable.pageSize) } - } ?: throw SusuException(ErrorCode.QUERY_DSL_NOT_EXISTS_ERROR) + SliceImpl(this, pageable, hasNext) + } + } ?: throw SusuException(ErrorCode.QUERY_DSL_NOT_EXISTS_ERROR) } fun StringPath.isEquals(parameter: String?): BooleanExpression? { diff --git a/domain/src/main/kotlin/com/oksusu/susu/domain/envelope/infrastructure/EnvelopeQRepository.kt b/domain/src/main/kotlin/com/oksusu/susu/domain/envelope/infrastructure/EnvelopeQRepository.kt index a6c3f071..82c21183 100644 --- a/domain/src/main/kotlin/com/oksusu/susu/domain/envelope/infrastructure/EnvelopeQRepository.kt +++ b/domain/src/main/kotlin/com/oksusu/susu/domain/envelope/infrastructure/EnvelopeQRepository.kt @@ -12,6 +12,7 @@ import com.oksusu.susu.domain.friend.domain.QFriend import com.oksusu.susu.domain.friend.domain.QFriendRelationship import com.oksusu.susu.domain.user.domain.QUser import com.querydsl.core.types.dsl.CaseBuilder +import com.querydsl.jpa.JPAExpressions import com.querydsl.jpa.impl.JPAQuery import jakarta.persistence.EntityManager import org.springframework.beans.factory.annotation.Autowired @@ -468,13 +469,22 @@ class EnvelopeQRepositoryImpl : EnvelopeQRepository, QuerydslRepositorySupport(E } override fun findLatestFriendEnvelopes(friendIds: Set): List { + /** sub query 질의를 위해, 별칭 지정 */ + val qSubEnvelope = QEnvelope("subEnvelope") + + /** 전달 기준 점에 대한 정보를 찾기 위한 sub query */ + val subQuery = JPAExpressions + .select(qSubEnvelope.handedOverAt.max()) + .from(qSubEnvelope) + .where(qSubEnvelope.friendId.eq(qEnvelope.friendId)) + return JPAQuery(entityManager) .select(qEnvelope) .from(qEnvelope) - .where(qEnvelope.friendId.`in`(friendIds)) - .groupBy(qEnvelope.friendId) - .having(qEnvelope.handedOverAt.eq(qEnvelope.handedOverAt.max())) - .fetch() + .where( + qEnvelope.friendId.`in`(friendIds), + qEnvelope.handedOverAt.eq(subQuery) + ).fetch() } override fun getMaxAmountEnvelopeInfoByUid(uid: Long, type: EnvelopeType): EnvelopeAndFriendModel? { diff --git a/gradle.properties b/gradle.properties index 54d027e6..3b7e26a8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version=1.1.23 +version=1.1.24 kotlin.code.style=official