Skip to content

Commit

Permalink
MARA-78 : FE API 연동 핫픽스 작업 (#39)
Browse files Browse the repository at this point in the history
* UserFriendResponse profileImage 추가

* count!! -> count 변경 및 초기값 0 설정

* count 쿼리 내 불필요한 offset, limit 제거
  • Loading branch information
jhkang1517 authored Feb 23, 2024
1 parent 72db573 commit 46f46ff
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ class CustomFriendshipRepositoryImpl(

val count = queryFactory.select(friendship.count()).from(friendship).innerJoin(friendship.toUser, appUser).on(
friendship.toUser.userId.eq(appUser.userId)
).where(friendship.fromUser.eq(user))
.offset(pageable.offset).limit(pageable.pageSize.toLong()).fetchOne()
).where(friendship.fromUser.eq(user)).fetchOne()

return PageableExecutionUtils.getPage(results, pageable) { count!! }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ class CustomIngredientDetailRepositoryImpl(
.offset(pageable.offset).limit(pageable.pageSize.toLong()).fetch()

val count = queryFactory.select(ingredientDetail.count()).from(ingredientDetail)
.where(ingredientDetail.refrigerator.eq(refrigerator).and(ingredientDetail.isDeleted.isFalse))
.offset(pageable.offset).limit(pageable.pageSize.toLong()).fetchOne()
.where(ingredientDetail.refrigerator.eq(refrigerator).and(ingredientDetail.isDeleted.isFalse)).fetchOne()

return PageableExecutionUtils.getPage(results, pageable) { count!! }
}
Expand All @@ -70,8 +69,7 @@ class CustomIngredientDetailRepositoryImpl(

override fun countByRefrigeratorList(refrigeratorList: List<Refrigerator>): Long {
val count = queryFactory.select(ingredientDetail.count()).from(ingredientDetail).where(
ingredientDetail.refrigerator.`in`(refrigeratorList)
.and(ingredientDetail.isDeleted.isFalse)
ingredientDetail.refrigerator.`in`(refrigeratorList).and(ingredientDetail.isDeleted.isFalse)
).fetchOne()

return count!!
Expand Down
20 changes: 10 additions & 10 deletions src/main/kotlin/mara/server/domain/share/ShareRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class CustomShareRepositoryImpl(
.limit(pageable.pageSize.toLong())
.orderBy(getOrder(sortBy)).fetch()

val count = queryFactory.select(share.count()).from(share).where(share.user.userId.`in`(friendsList).and(share.status.eq(status))).offset(pageable.offset)
.limit(pageable.pageSize.toLong()).fetchOne()
val count = queryFactory.select(share.count()).from(share)
.where(share.user.userId.`in`(friendsList).and(share.status.eq(status))).fetchOne()

return PageableExecutionUtils.getPage(query, pageable) { count!! }
}
Expand All @@ -59,8 +59,9 @@ class CustomShareRepositoryImpl(
.limit(pageable.pageSize.toLong())
.orderBy(share.createdAt.desc()).fetch()

val count = queryFactory.select(share.count()).from(share).where(share.user.eq(user).and(share.status.eq(status))).offset(pageable.offset)
.limit(pageable.pageSize.toLong()).fetchOne()
val count =
queryFactory.select(share.count()).from(share).where(share.user.eq(user).and(share.status.eq(status)))
.fetchOne()

return PageableExecutionUtils.getPage(query, pageable) { count!! }
}
Expand All @@ -81,9 +82,7 @@ class CustomShareRepositoryImpl(

val count = queryFactory.select(share.count()).from(applyShare)
.join(applyShare.share, share)
.where(applyShare.user.eq(user).and(share.status.eq(status))).offset(pageable.offset)
.limit(pageable.pageSize.toLong())
.fetchOne()
.where(applyShare.user.eq(user).and(share.status.eq(status))).fetchOne()

return PageableExecutionUtils.getPage(query, pageable) { count!! }
}
Expand All @@ -95,16 +94,17 @@ class CustomShareRepositoryImpl(
.fetch()

val query = queryFactory.selectFrom(share)
.where(share.id.`in`(appliedShareIdList).and(share.user.eq(user).and(share.status.eq(status)))).offset(pageable.offset)
.where(share.id.`in`(appliedShareIdList).and(share.user.eq(user).and(share.status.eq(status))))
.offset(pageable.offset)
.limit(pageable.pageSize.toLong())
.orderBy(share.createdAt.desc()).fetch()

val count = queryFactory.select(share.count()).from(share)
.where(share.id.`in`(appliedShareIdList).and(share.user.eq(user).and(share.status.eq(status)))).offset(pageable.offset)
.limit(pageable.pageSize.toLong()).fetchOne()
.where(share.id.`in`(appliedShareIdList).and(share.user.eq(user).and(share.status.eq(status)))).fetchOne()

return PageableExecutionUtils.getPage(query, pageable) { count!! }
}

private fun getOrder(sortBy: String): OrderSpecifier<*> {
val orderSpecifier = when (sortBy) {
registeredDate -> share.createdAt.desc()
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/mara/server/domain/user/UserDto.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ class UserInviteCodeResponse(
class UserFriendResponse(
val userId: Long,
val nickname: String,
val profileImage: ProfileImage,
val ingredientCount: Long
) {
constructor(user: User, ingredientCount: Long) : this(
userId = user.userId,
nickname = user.nickname,
profileImage = user.profileImage,
ingredientCount = ingredientCount
)
}

0 comments on commit 46f46ff

Please sign in to comment.