Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jombidev committed Apr 17, 2024
2 parents e8a5268 + fafb500 commit bd71785
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import com.molohala.infinitycore.comment.application.dto.res.CommentRes

interface QueryCommentRepository {
fun findByCommunityId(communityId: Long):List<CommentRes>?
fun findRecentComment(communityId: Long):CommentRes
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ class QueryDslCommentRepository(
.fetch()
}

override fun findRecentComment(communityId: Long): CommentRes? {
return queryFactory.select(commentProjection())
.from(comment)
.where(comment.communityId.eq(communityId))
.orderBy(comment.createdAt.desc())
.innerJoin(member)
.on(comment.memberId.eq(member.id))
.fetchFirst()
}


private fun commentProjection(): ConstructorExpression<CommentRes> {
return Projections.constructor(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.molohala.infinitycore.community.application.dto.res

import com.molohala.infinitycore.comment.application.dto.res.CommentRes

data class CommunityListRes(
val community: CommunityRes,
val recentComment: CommentRes
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package com.molohala.infinitycore.community.application.service

import com.molohala.infinitycommon.exception.GlobalExceptionCode
import com.molohala.infinitycommon.exception.custom.CustomException
import com.molohala.infinitycore.comment.application.dto.res.CommentRes
import com.molohala.infinitycore.comment.repository.QueryCommentRepository
import com.molohala.infinitycore.common.PageRequest
import com.molohala.infinitycore.community.application.dto.req.CommunityModifyReq
import com.molohala.infinitycore.community.application.dto.req.CommunitySaveReq
import com.molohala.infinitycore.community.application.dto.res.CommunityListRes
import com.molohala.infinitycore.community.application.dto.res.CommunityRes
import com.molohala.infinitycore.community.domain.consts.CommunityState
import com.molohala.infinitycore.community.domain.entity.Community
Expand All @@ -24,6 +27,7 @@ import org.springframework.transaction.annotation.Transactional
class CommunityService(
private val communityJpaRepository: CommunityJpaRepository,
private val queryCommunityRepository: QueryCommunityRepository,
private val queryCommentRepository: QueryCommentRepository,
private val queryLikeRepository: QueryLikeRepository,
private val memberSessionHolder: MemberSessionHolder
) {
Expand All @@ -39,10 +43,10 @@ class CommunityService(
)
}

fun getList(page: PageRequest): List<CommunityRes> {
fun getList(page: PageRequest): List<CommunityListRes> {
if (page.page < 1) throw CustomException(GlobalExceptionCode.INVALID_PARAMETER)
return queryCommunityRepository.findWithPagination(page)
.map {
return queryCommunityRepository.findWithPagination(page).map {
CommunityListRes(
CommunityRes(
it.communityId,
it.content,
Expand All @@ -51,8 +55,9 @@ class CommunityService(
queryLikeRepository.existsByCommunityIdAndMemberId(it.communityId,it.writerId),
it.writerName,
it.writerId
)
}
), queryCommentRepository.findRecentComment(it.communityId)
)
}
}

fun getById(id: Long): CommunityRes? {
Expand Down

0 comments on commit bd71785

Please sign in to comment.